home *** CD-ROM | disk | FTP | other *** search
/ Internet Tools (InfoMagic) / Internet Tools.iso / dos_win / winsock / wsock20 / ws2api.txt < prev    next >
Text File  |  1994-12-16  |  191KB  |  4,245 lines

  1.  
  2.  
  3.                               
  4.                               
  5.                               
  6.                       Windows Sockets 2
  7.               Application Programming Interface
  8.  
  9.                               
  10.                               
  11.       An Interface for Transparent Network Programming
  12.                   Under Microsoft WindowsTM
  13.                               
  14.                               
  15.                         Revision 2.0
  16.                          Dec 8, 1994
  17.                               
  18.                           Winsock 2
  19.                               
  20.                               
  21.                          Preliminary
  22.               Subject to Change Without Notice
  23.                               
  24.                               
  25.                               
  26.                               
  27.                               
  28.                               
  29.                               
  30.                               
  31.                               
  32.                               
  33.                               
  34.           Microsoft,  Intel and JSB  disclaim  all
  35.           warranties and liability for the use  of
  36.           this   document   and  the   information
  37.           contained   herein,   and   assumes   no
  38.           responsibility for any errors which  may
  39.           appear  in  this  document.   Microsoft,
  40.           Intel  and  JSB  make  no  warranty   or
  41.           license  regarding the  relationship  of
  42.           this   document   and  the   information
  43.           contained  herein  to  the  intellectual
  44.           property rights of any party. Microsoft,
  45.           Intel  and  JSB  make no  commitment  to
  46.           update the information contained herein.
  47.                       Table of Contents
  48.  
  49.  Introduction                                             4
  50.  
  51.  Summary of Additions and Changes                         4
  52.   Support for multiple transports simultaneously          4
  53.   Shared Sockets                                          5
  54.   Overlapped I/O and Event Objects                        5
  55.   Socket Groups                                           7
  56.   Enhanced Functionality During Connection Setup          7
  57.   Quality of Service                                      7
  58.   New Socket Option Summary                               9
  59.  
  60.  New API Functions                                       10
  61.   WSAAccept()                                            10
  62.   WSAAsyncSelect()                                       15
  63.   WSAConnect()                                           21
  64.   WSADuplicateSocket()                                   26
  65.   WSAEnumProtocols()                                     28
  66.   WSAEnumNetworkEvents()                                 31
  67.   WSAEventSelect()                                       33
  68.   WSARecv()                                              38
  69.   WSARecvfrom()                                          41
  70.   WSASend()                                              45
  71.   WSASendto()                                            48
  72.   WSASocket()                                            52
  73.   WSACreateEvent                                         54
  74.   WSACloseEvent                                          55
  75.   WSAWaitForMultipleEvents                               56
  76.   WSASetEvent                                            58
  77.   WSAResetEvent                                          59
  78.   WSAGetOverlappedResult                                 60
  79.   WSAGetQoSByName                                        62
  80.  
  81.  Winsock 2.0 Header File - Winsock2.h                    63
  82.  
  83.  Introduction
  84. The pages which follow contain new APIs that are proposed
  85. for Winsock 2.  Except where indicated, they are applicable
  86. to both 16 and 32 bit programming environments.  These APIs
  87. were developed jointly by the Generic API Extensions and
  88. Operating Framework functionality groups from within the
  89. Winsock Forum.
  90.  
  91. Summary of Additions and Changes
  92. The paragraphs which follow summarize the major changes and
  93. additions in going from Winsock 1.1 to Winsock 2.
  94. Support for multiple transports simultaneously
  95. Winsock 1.1 implementations are all vendor-specific since no
  96. standard interface has been defined for use between
  97. Winsock.DLL and protocol stacks.  Winsock 2 changes the
  98. model by defining such an interface and allowing multiple
  99. stacks from multiple vendors to be accessed simultaneously
  100. from a single Winsock2 DLL.  Furthermore, Winsock 2 support
  101. is not limited to TCP/IP protocol stacks as is the case for
  102. Winsock 1.1.
  103.  
  104. This is accomplished by creating a formal Service Provider
  105. Interface Specification, which exists under separate cover.
  106. Included in the SPI document is a definition for a set of
  107. functions provided in the Winsock2 DLL  for the use of
  108. transport providers in installing their transport and making
  109. them available via Winsock.  This obviates the need for
  110. providers to deal with the differences between INI files in
  111. Windows 3 environments and the registry in Windows 95 and
  112. NT.
  113.  
  114. Some of the elements in the WSAData structure (obtained via
  115. a call to WSAStartup()) should now be ignored since they no
  116. longer apply to a single vendor's stack.  These include:
  117. iMaxSockets, iMaxUdpDg, and lpVendorInfo.  Two new socket
  118. options are introduced to supply provider-specific
  119. information: SO_MAX_MSG_SIZE (replaces the iMaxUdpDg
  120. element) and PVD_CONFIG (allows any other provider-specific
  121. configuration to occur).
  122.  
  123. An application may use WSAEnumProtocols() to discover which
  124. transport providers are present and learn information about
  125. each as contained in an associated PROTOCOL_INFO struct.
  126. Whereas in Winsock 1 there was a small number of well-known
  127. socket types and protocol identifiers, the focus will shift
  128. for Winsock 2.  The existing socket type and protocol
  129. identifiers will be retained for compatibility reasons, but
  130. many new address family, socket type and protocol values are
  131. expected to appear which are unique but not necessarily well
  132. known.  Applications that desire to be independent of
  133. particular protocols are encouraged to examine the
  134. PROTOCOL_INFO structure associated with each available
  135. transport and select those that offer the required
  136. communications attributes (e.g. message vs. byte-stream
  137. oriented, reliable vs. unreliable, etc.).  Having found one
  138. or more transports with suitable attributes, it really won't
  139. matter which particular socket type or protocol values are
  140. associated with the transport.  These values are simply
  141. copied out of the PROTOCOL_INFO struct and used as
  142. parameters to the socket() or WSASocket() function.
  143.  
  144. It is anticipated that a clearinghouse will be established
  145. for obtaining unique identifiers for new address families,
  146. socket types and protocols.  FTP and Web servers will supply
  147. current identifier/value mappings, and email can be used to
  148. obtain new ones.
  149.  
  150. Restrictions on select()
  151. In Winsock 2 the FD_SET supplied to the select() function
  152. will be constrained to contain sockets from a single service
  153. provider.  This restriction allows the Win32 implementations
  154. of Winsock2.DLL to be much simpler than they would otherwise
  155. be since all blocking behavior may now be implemented by the
  156. transport provider directly.  (Unfortunately not true for
  157. Win16!)  This does not in any way restrict an application
  158. from having multiple sockets open using multiple providers.
  159. When non-blocking operations are preferred the
  160. WSAAsyncSelect() function is the solution.  Since it takes a
  161. socket handle as an input parameter, it doesn't matter what
  162. provider is associated with the socket.
  163.  
  164. When an application needs to block waiting for I/O to occur
  165. on a set of sockets which spans multiple providers, the
  166. recommended solution is to use WSAWaitForMultipleEvents().
  167. The application may also which to take advantage of the
  168. WSAEventSelect() function which also allows the FD_XXX
  169. network events to be associated with an event object and
  170. handled from within the event object paradigm.
  171.  
  172.  
  173.      
  174. Shared Sockets
  175. WSADuplicateSocket() is introduced to enable socket sharing
  176. by creating a shared socket for a target task (which could
  177. be the same task) with respect to a local, existing socket.
  178. The new shared socket thus created is only meaningful within
  179. the context of the target task.  This mechanism is designed
  180. to be appropriate for both single-threaded version of
  181. Windows (such as Windows 3.1) and preemptive multithreaded
  182. versions of Windows (such as Windows 95 and NT).
  183.  
  184. Overlapped I/O and Event Objects
  185. Winsock 2 introduces overlapped (or asynchronous) I/O and
  186. requires that all transport providers support this
  187. capability. Overlapped  I/O can be performed only on sockets
  188. that were created via the WSASocket() function with the
  189. WSA_FLAG_OVERLAPPED flag set, and will follow the model
  190. established in Win32.
  191.  
  192.  For receiving, application's use WSARecv() or WSARecvFrom()
  193. to supply buffers into which data is to be received prior to
  194. the time when data is received by the network.  As data
  195. arrives, the network places it directly into the
  196. application's buffer and thereby avoids the copy operation
  197. that would otherwise occur at the time the recv() or
  198. recvfrom() function is invoked.  Note that if data arrives
  199. when no receive buffers have been posted by the application,
  200. the network resorts to the familiar synchronous style of
  201. operation where the incoming data is buffered internally
  202. until such time as the application issues a receive call and
  203. thereby supplies a buffer into which the data may be copied.
  204. An exception to this would be if the application used
  205. setsockopt() to set the size of the receive buffer to zero.
  206. In this instance, data received without a receive buffer
  207. being posted would be lost.
  208.  
  209. On the sending side, applications use WSASend() or
  210. WSASendTo() to supply pointers to filled buffers and then
  211. agree to not disturb the buffers in any way until such time
  212. as the network has consumed the buffer's contents.
  213.  
  214. Overlapped  send and receive calls return immediately and
  215. the network provides a subsequent indication when send
  216. buffers have been consumed or when receive buffers are full.
  217. Also, both send and receive operations can be overlapped.
  218. The receive functions may be invoked multiple times to post
  219. receive buffers in preparation for incoming data, and the
  220. send functions may be invoked multiple times to queue up
  221. multiple buffers to be sent.  Note that while the
  222. application can rely upon a series of overlapped send
  223. buffers  being sent in the order supplied, the corresponding
  224. completion indications may occur in a different order.
  225. Likewise, on the receiving side, buffers will be filled in
  226. the order they are supplied but the completion indications
  227. may occur in a different order.
  228.  
  229. Event Objects as an Underpinning for Completion Indication
  230. Introducing overlapped I/O requires a mechanism for
  231. applications to unambiguously associate send and receive
  232. requests with their subsequent completion indications.  The
  233. selected mechanism utilizes event objects which are modeled
  234. after Win32 events. Applications use WSACreateEvent () to
  235. obtain an async event handle which may then be supplied as a
  236. required parameter to the asynchronous versions of send and
  237. receive calls (WSASend(), WSASendTo(), WSARecv(),
  238. WSARecvFrom()).  The event object, which is cleared when
  239. first created, is set by the network when the associated
  240. overlapped I/O operation has completed (either successfully
  241. or with errors).
  242.  
  243. In order to provide applications with appropriate levels of
  244. flexibility, several options are available for receiving
  245. completion indications. These include: waiting on (i.e.
  246. blocking on) event objects, polling event objects, and
  247. callbacks (for 16 bit environments) or asynchronous
  248. procedure calls (for 32 bit environments).
  249.  
  250. Blocking and waiting for Completion Indication -
  251. Applications may also choose to block while waiting for one
  252. or more async events to become set using
  253. WSAWaitForMultipleEvents(). In Win16 implementations, this
  254. will utilize a blocking hook as is currently provided for
  255. standard blocking socket operations.  In Win32
  256. implementations, the process or thread will be truly
  257. blocked.  Since Winsock 2 event objects are implemented as
  258. Win32 events, the native Win32 function
  259. WaitForMultipleObjects() may also be used for this purpose.
  260. This is especially useful if the thread needs to wait on
  261. both socket and non-socket events.
  262.  
  263.  
  264. Polling for Completion Indication -
  265. Applications which prefer not to block may use
  266. WSAGetOverlappedResults() to poll for the completion status
  267. associated with any particular event object.  This function
  268. will indicate both whether or not the overlapped operation
  269. has completed, and error status when completion has
  270. occurred.
  271.  
  272. Using callbacks or APCs -
  273. The functions used to initiate overlapped I/O (WSASend,
  274. WSASendTo, WSARecv, WSARecvFrom) all take
  275. lpCompletionRoutine as an input parameter.  This is a
  276. pointer to an application-specified function that is called
  277. when the overlapped I/O operation has completed
  278. (successfully or otherwise).  In Win16 environments,
  279. callback functions may be invoked in what is essentially
  280. interrupt context.  Consequently, applications have a very
  281. limited set of Windows and runtime library function calls
  282. that can be safely made.  Network transports will allow send
  283. and receive operations to be called within the context of
  284. the callback function.
  285.  
  286. In Windows 95 and NT, the completion function  will occur as
  287. an asynchronous procedure call (APC) and requires that the
  288. thread be in an alertable wait state such as can occur with
  289. the function WSAWaitForMultipleEvents().
  290.  
  291. Relationship of WSAGetXByY() asynchronous task handles to
  292. event objects -
  293. The Winsock 1.1 spec includes a number of asynchronous
  294. database access routines known collectively as the
  295. WSAGetxByY functions.  The return value for these is
  296. referred to as an "asynchronous task handle".  In Winsock 2,
  297. these asynchronous task handles are, in fact, event objects.
  298. As such they can be waited on by either using
  299. WSAWaitForMultipleEvents() (or in Win32 by using
  300. WaitForMultipleObjects()), or they can be polled with
  301. WSAGetOverlappedResults().
  302.  
  303. Editor's Note:
  304. This represents an exception to the normal way of doing
  305. things in a couple of areas.  First, since these routines
  306. also generate a Windows message to indicate completion, the
  307. convention of allowing only a single completion indication
  308. mechanism in place at one time is violated.  Secondly, while
  309. the established notion has been that applications create
  310. event objects and then explicitly associate them with some
  311. indication, this is not followed here since the function
  312. invocation causes an event object to come into existence as
  313. a side effect.  The application may explicitly destroy the
  314. event object after the routine completes using
  315. WSACloseEvent(), or it may allow the Winsock 2 DLL to just
  316. recycle the event object at some future (unspecified) time
  317. as is the case for Winsock 1.1's asynchronous task handles.
  318.  
  319. If we felt that these WSAGetXbyY() routines had a long life
  320. ahead of them, we would be a lot more bothered by these
  321. inconsistencies than we are.  But we hope that their use is
  322. soon superseded by the much more capable Winsock 2 name
  323. resolution routines.  This being the case, we prefer to note
  324. but ignore the inconsistencies pointed out above.
  325.  
  326.  
  327.  
  328. Socket Groups
  329. Winsock 2 introduces the notion of a socket group as a means
  330. for an application (or cooperating set of applications) to
  331. indicate to an underlying service provider that a particular
  332. set of sockets are related and that the group thus formed
  333. has certain attributes.  Group attributes include relative
  334. priorities of the individual sockets within the group and a
  335. group quality of service specification.
  336.  
  337. Applications needing to exchange multimedia streams over the
  338. network are benefited by being able to establish a specific
  339. relationship among the set of sockets being utilized.  As a
  340. minimum this might include a hint to the service provider
  341. about the relative priorities of the media streams being
  342. carried.  For example, a conferencing application would want
  343. to have the socket used for carrying the audio stream be
  344. given higher priority than that of the socket used for the
  345. video stream.  Furthermore, there are transport providers
  346. (e.g. digital telephony and ATM) which can utilize a group
  347. quality of service specification to determine the
  348. appropriate characteristics for the underlying call.  The
  349. sockets within this group would then be multiplexed in the
  350. usual manner over this call.  By allowing the application to
  351. identify the sockets that make up a group and to specify the
  352. required group attributes, such service providers can
  353. operate with maximum effectiveness.
  354.  
  355. WSAConnect () and WSAAccept () are two new functions used to
  356. explicitly create and/or join a socket group coincident with
  357. establishing or accepting a socket connection.  Socket group
  358. IDs can be retrieved by using getsockopt() with option
  359. SO_GROUP_ID.  Relative priority can be accessed by using
  360. get/setsockopt() with option SO_GROUP_PRIORITY.
  361.  
  362.  
  363. Enhanced Functionality During Connection Setup
  364. WSAAccept () allows an application to obtain caller
  365. information before deciding whether or not to accept an
  366. incoming connection request.  This is done via a callout to
  367. an application-supplied condition function.
  368. User-to-user data may be specified in WSAConnect () and/or
  369. the condition function of WSAAccept () to be transferred to
  370. the peer during connection establishment, provided this
  371. feature is supported by the service provider.
  372.  
  373.  
  374. Quality of Service
  375. The basic QOS mechanism in Winsock 2 descends from the flow
  376. specification (or "flow spec") as described by Craig
  377. Partridge in RFC 1363, dated September 1992.  A brief
  378. overview of this concept is as follows:
  379.  
  380.  Flow specs describe a set of characteristics about a
  381. proposed connection-oriented, unidirectional flow through
  382. the network.  An application may associate a pair of flow
  383. specs with a socket at the time a connection request is
  384. made.  Flow specs indicate parametrically what level of
  385. service is required and also stipulate whether the
  386. application is willing to be flexible if the requested level
  387. of service is not available. After a connection is
  388. established, the application may retrieve the flow specs
  389. associated with the socket and examine the contents to
  390. discover the level of service that the network is willing
  391. and/or able to provide.  If the service provided is not
  392. acceptable, the application may close the socket and take
  393. whatever action is appropriate (e.g. scale back and ask for
  394. a lower quality of service, try again later, notify the user
  395. and exit, etc.)
  396.  
  397. Even after a flow is established, conditions in the network
  398. may change resulting in a reduction (or increase) in the
  399. available service level.  A notification mechanism is
  400. included which utilizes the usual  Winsock 2 notification
  401. techniques to indicate to the application that QOS levels
  402. have changed.  The app should again retrieve the
  403. corresponding flow specs and examine them in order to
  404. discover what aspect of the service level has changed.
  405.  
  406. The flow specs proposed for Winsock 2 divide QOS
  407. characteristics into the following general areas:
  408.  
  409. 1.Network bandwidth utilization - The manner in which the
  410.   application's traffic will be injected into the network.
  411.   This includes specifications for average bandwidth
  412.   utilization, peak bandwidth, and maximum burst duration.
  413.  
  414. 2.Latency - Upper limits on the amount of delay and delay
  415.   variation that are acceptable.
  416.  
  417. 3.Level of service guarantee -  Whether or not an absolute
  418.   guarantee is required as opposed to best effort.  Note
  419.   that providers which have no feasible way to provide the
  420.   level of service requested are expected to  fail the
  421.   connection attempt.
  422.  
  423. 4.Cost -  This is a place holder for a future time when a
  424.   meaningful cost metric can be determined.
  425.  
  426. 5.Provider-specific parameters - The flow spec itself can
  427.   be extended in ways that are particular to specific
  428.   providers, and the assumed provider can be identified.
  429.  
  430.  
  431. An application indicates its desire for a non-default flow
  432. spec at the time a connection request is made (see
  433. WSAConnect () and WSAAccept()).  Since establishing a flow
  434. spec'd connection is likely to involve cooperation and/or
  435. negotiation between intermediate routers and hosts, the
  436. results of a flow spec request cannot be determined until
  437. after the connection operation is fully completed.  After
  438. this time, the application may use getsockopt() to retrieve
  439. the resulting flow spec structure so that it can determine
  440. what the network was willing and/or able to supply.
  441.  
  442. The Flow Spec Structures
  443. The Winsock 2 flow spec structure is defined in Winsock2.h
  444. and is reproduced here.
  445.  
  446. typedef enum
  447. {
  448.      GuaranteedService,
  449.      BestEffortService
  450. } GUARANTEE;
  451.  
  452. typedef struct _flowparams
  453. {
  454.      int64          AverageBandwith;// In Bytes/sec
  455.      int64          PeakBandwidth; // In Bytes/sec
  456.      int64          BurstLength;   // In microseconds
  457.      int64          Latency;  // In microseconds
  458.      int64          DelayVariation;// In microseconds
  459.      GUARANTEE levelOfGuarantee;// Guaranteed or
  460.                          // Best Effort
  461.      int32          CostOfCall;    // Reserved for future
  462.                          // use, must be set to 0
  463.      int32          SizePSP;  // Length of provider
  464.                          // specific parameters
  465.           UCHAR     ProviderSpecificParams[1];// provider
  466. specific                                          //
  467. parameters
  468. } FLOWPARAMS;
  469.  
  470. typedef struct _QualityOfService
  471. {
  472.      FLOWPARAMS     ForwardFP;     // Caller(Initiator) to
  473. callee
  474.      FLOWPARAMS     BackwardFP;    // Callee to caller
  475. } QOS, FAR * LPQOS;
  476.           
  477. Default Values
  478. A default flow spec is associated with each eligible socket
  479. at the time it is created.  Field values for this default
  480. flow spec are indicated below.  In all cases these values
  481. indicate that no particular flow characteristics are being
  482. requested from the network.  Applications only need to
  483. modify values those fields which they are interested in, but
  484. must be aware that there exists some coupling between
  485. fields.
  486.  
  487. AverageBandwidth =  0, not specified
  488. PeakBandwidth =     0, not specified
  489. BurstLength =       0, not specified
  490. Latency =      0, not specified
  491. DelayVariation =    0, not specified
  492. LevelOfGuarantee =  BEST_EFFORT
  493. CostOfCall =        0, reserved for future use
  494. ProviderSpecificParams = 0, none supplied
  495.  
  496.  
  497. New Socket Option Summary
  498. The new socket options proposed for Winsock2 are summarized
  499. in the following table.
  500.  
  501. Value           Type      Meaning            Default      Not
  502.                                                           e
  503. SO_MAX_MSG_SIZE int       Maximum size of a  Implementat  get
  504.                           message for        ion          onl
  505.                           message-oriented   dependent    y
  506.                           socket types. Has
  507.                           no meaning for
  508.                           stream-oriented
  509.                           sockets.
  510. SO_FLOWSPEC     char FAR  The flow spec of   NULL         get
  511.                 *         this socket.                    onl
  512.                                                           y
  513. SO_GROUP_ID     GROUP     The identifier of  NULL         get
  514.                           the group to                    onl
  515.                           which this socket               y
  516.                           belongs.
  517. SO_GROUP_FLOWSP char FAR  The flow spec of   NULL         get
  518. EC              *         the socket group                onl
  519.                           to which this                   y
  520.                           socket belongs.
  521. SO_GROUP_PRIORI int       The relative       0            
  522. TY                        priority for
  523.                           sockets that are
  524.                           part of a socket
  525.                           group.
  526. SO_PROTOCOL_INF struct    Description of     protocol     get
  527. O               PROTOCOL  protocol info for  dependent    onl
  528.                 _INFO     protocol that is                y
  529.                           bound to this
  530.                           socket.
  531. PVD_CONFIG      char FAR  An opaque data     Implementat  
  532.                 *         structure object   ion
  533.                           containing         dependent
  534.                           configuration
  535.                           information of
  536.                           the service
  537.                           provider.
  538.  
  539.  
  540.  
  541. New API Functions
  542.  
  543. WSAAccept()
  544. Description    Conditionally accept a connection based on
  545.           the return value of a condition function, and
  546.           optionally create and/or join a socket group.
  547.  
  548.           #include <winsock2.h>
  549.  
  550.           SOCKET WSAAPI WSAAccept ( SOCKET s, struct
  551.           sockaddr FAR * addr, int FAR * addrlen,
  552.           LPCONDITIONPROC lpfnCondition, DWORD
  553.           dwCallbackData );
  554.  
  555.           
  556.           s          A descriptor identifying a socket which
  557.                     is listening for connections after a
  558.                     listen().
  559.           
  560.           addr      An optional pointer to a buffer which
  561.                     receives the address of the connecting
  562.                     entity, as known to the communications
  563.                     layer.  The exact format of the addr
  564.                     argument is determined by the address
  565.                     family established when the socket was
  566.                     created.
  567.           
  568.           addrlen   An optional pointer to an integer which
  569.                     contains the length of the address addr.
  570.           
  571.           lpfnCondition  The procedure instance address of
  572.                     the optional, application-supplied
  573.                     condition function which will make an
  574.                     accept/reject decision based on the
  575.                     caller information passed in as
  576.                     parameters, and optionally create and/or
  577.                     join a socket group by assigning an
  578.                     appropriate value to the result
  579.                     parameter g of this function.
  580.           
  581.           dwCallbackData The callback data passed back to
  582.                     the application as a condition function
  583.                     parameter.  This parameter is not
  584.                     interpreted by Winsock.
  585.  
  586. Remarks   This routine extracts the first connection on the
  587.           queue of pending connections on s, and checks it
  588.           against the condition function, provided the
  589.           condition function is specified (i.e., not NULL).
  590.           If the condition function returns CF_ACCEPT, this
  591.           routine creates a new socket with the same
  592.           properties as s and returns a handle to the new
  593.           socket, and then optionally creates and/or joins a
  594.           socket group based on the value of the result
  595.           parameter g in the condition function.  If the
  596.           condition function returns CF_REJECT, this routine
  597.           rejects the connection request.  The condition
  598.           function runs in the same thread as this routine
  599.           does, and should return as soon as possible.  If
  600.           the decision cannot be made immediately, the
  601.           condition function should return CF_DEFER to
  602.           indicate that no decision has been made, and no
  603.           action about this connection request should be
  604.           taken by the service provider.  When the
  605.           application is ready to take action on the
  606.           connection request, it may invoke WSAAccept()
  607.           again and return either CF_ACCEPT or CF_REJECT as
  608.           a return value from the condition function.
  609.  
  610.           For synchronous sockets which remain in the
  611.           (default) blocking mode, if no pending connections
  612.           are present on the queue, WSAAccept() blocks the
  613.           caller until a connection is present.  For
  614.           synchronous sockets in a non-blocking mode or for
  615.           overlapped sockets, if this function is called
  616.           when no pending connections are present on the
  617.           queue, WSAAccept() returns an error as described
  618.           below.  The accepted socket may not be used to
  619.           accept more connections.  The original socket
  620.           remains open.
  621.           
  622.           The argument addr is a result parameter that is
  623.           filled in with the address of the connecting
  624.           entity, as known to the communications layer.  The
  625.           exact format of the addr parameter is determined
  626.           by the address family in which the communication
  627.           is occurring.  The addrlen is a value-result
  628.           parameter; it should initially contain the amount
  629.           of space pointed to by addr.  On return, it will
  630.           contain the actual length (in bytes) of the
  631.           address returned.  This call is used with
  632.           connection-oriented socket types such as
  633.           SOCK_STREAM.  If addr and/or addrlen are equal to
  634.           NULL, then no information about the remote address
  635.           of the accepted socket is returned. .  Otherwise,
  636.           these two parameters will be filled in regardless
  637.           of whether the condition function is specified or
  638.           what it returns.
  639.  
  640.           The prototype of the condition function is as
  641.           follows:
  642.           
  643.                int PASCAL FAR ConditionFunc(
  644.                     const struct sockaddr FAR * CallerName,
  645.                     int CallerNamelen,
  646.                     LPWSABUF lpCallerData,
  647.                     LPQOS lpCallerSFlowspec,
  648.                     const struct sockaddr FAR * Calleename,
  649.                     int CalleeNamelen,
  650.                     LPWSABUF lpCalleeData,
  651.                     GROUP FAR * g,
  652.                     DWORD dwCallbackData );
  653.           
  654.           {How about group QOS?  Let's leave it out for now
  655.           since:
  656.             1) It adds complexity
  657.             2) We aren't sure we need it
  658.             3) It isn't for sure that group info comes
  659.           across the wire}
  660.           
  661.           LPWSABUF and LPQOS are defined in winsock2.h as
  662.           follows:
  663.           
  664.                typedef struct _WSABUF {
  665.                     int       len;      // the length of the
  666.           buffer
  667.                     char FAR *     buf; // the pointer to
  668.           the buffer
  669.                } WSABUF, FAR * LPWSABUF;
  670.           
  671.                typedef enum
  672.                {
  673.                     GuaranteedService,
  674.                     BestEffortService
  675.                } GUARANTEE;
  676.  
  677.                typedef struct _flowparams
  678.                {
  679.                     int64          AverageBandwith;// In
  680. Bytes/sec
  681.                          int64          PeakBandwidth; // In
  682. Bytes/sec
  683.                          int64          BurstLength;   // In
  684. microseconds
  685.                     int64          Latency;       // In
  686. microseconds
  687.                     int64          DelayVariation;     // In
  688. microseconds
  689.                     GUARANTEE levelOfGuarantee;// Guaranteed
  690. or
  691.                                         // Best Effort
  692.                     int32          CostOfCall;    //
  693. Reserved for future
  694.                                         // use, must be set
  695. to 0
  696.                     int32          ProviderId;    //
  697. Provider Identifier
  698.                     int32          SizePSP;  // Length of
  699. provider
  700.                                         // specific
  701. parameters
  702.                          UCHAR
  703. ProviderSpecificParams[1];// provider specific
  704. // parameters
  705.                } FLOWPARAMS;
  706.  
  707.                typedef struct _QualityOfService
  708.                {
  709.                     FLOWPARAMS     ForwardFP;     //
  710. Caller(Initiator) to callee
  711.                     FLOWPARAMS     BackwardFP;    // Callee
  712. to caller
  713.                } QOS, FAR * LPQOS;
  714.           
  715.           ConditionFunc is a placeholder for the application-
  716.           supplied function name.  In 16-bit Windowns
  717.           environments, it is invoked in the same thread as
  718.           WSAAccept(), thus no other Winsock functions can
  719.           be called except WSAIsBlocking() and
  720.           WSACancelBlockingCall().  The actual condition
  721.           function must reside in a DLL or application
  722.           module and be exported in the module definition
  723.           file.  You must use MakeProcInstance() to get a
  724.           procedure-instance address for the callback
  725.           function. The s parameter is the socket descriptor
  726.           of the listening socket specified in
  727.           WSAAcceptEx().
  728.           
  729.           The lpCallerId and lpCallerData are value
  730.           parameters which contain the address of the
  731.           connecting entity and any user data that was sent
  732.           along with the connection request, respectively.
  733.           
  734.           lpCallerSFlowspec, and iSFlowspecLen contains two
  735.           blocks of memory containing the flow specs for
  736.           socket s, one for each direction, specified by the
  737.           caller. The forward or backward QOS values will be
  738.           set to NULL as appropriate for any unidirectional
  739.           sockets..  The first part of each memory block is
  740.           struct FLOWSPEC, optionally followed by any
  741.           service provider specific portion.  Thus,
  742.           lpSFlowspec->Flen and lpSFlowspec->Blen must be
  743.           larger than or equal to the size of struct
  744.           FLOWSPEC.  A NULL value for lpSFlowspec indicates
  745.           no caller supplied flow spec.
  746.           
  747.           The lpCalleeId is a value parameter which contains
  748.           the local address of the connected entity. The
  749.           lpCalleeData is a result parameter used by the
  750.           condition function to supply user data back to the
  751.           connecting entity.  lpCalleeData->len initially
  752.           contains the length of the buffer allocated by the
  753.           service provider and pointed to by lpCalleeData-
  754.           >buf.  A value of zero means passing user data
  755.           back to the caller is not supported.  The
  756.           condition function should copy up to lpCalleeData-
  757.           >len  bytes of data into lpCalleeData->buf , and
  758.           then update lpCalleeData->len to indicate the
  759.           actual number of bytes transferred.  If no user
  760.           data is to be passed back to the caller, the
  761.           condition function should set lpCalleeData->len to
  762.           zero.  The  format of all address and user data is
  763.           specific to the address family to which the socket
  764.           belongs.
  765.           
  766.           The result parameter g is assigned within the
  767.           condition function to indicate the following
  768.           actions:
  769.                if g is an existing socket group id, add s to
  770.           this group, provided all the
  771.           requirements set by this group are met; or
  772.                if g = SG_UNCONSTRAINED_GROUP, create an
  773.           unconstrained socket               group and have
  774.           s as the first member; or
  775.                if g = SG_CONSTRAINED_GROUP, create a
  776.           constrained socket group and            have s as
  777.           the first member; or
  778.                if g = NULL, no group operation is performed.
  779.           For unconstrained groups, any set of sockets may
  780.           be grouped together as long as they are supported
  781.           by a single service provider and are connection-
  782.           oriented.  A constrained socket group further
  783.           requires that connections on all grouped sockets
  784.           be to the same host.  For newly created socket
  785.           groups, the new group id can be retrieved by using
  786.           getsockopt() with option SO_GROUP_ID, if this
  787.           operation completes successfully.
  788.           
  789.  
  790. Return Value   If no error occurs, WSAAccept() returns a
  791.           value of type SOCKET which is a descriptor for the
  792.           accepted socket.  Otherwise, a value of
  793.           INVALID_SOCKET is returned, and a specific error
  794.           code may be retrieved by calling
  795.           WSAGetLastError().
  796.  
  797.           The integer referred to by addrlen initially
  798.           contains the amount of space pointed to by addr.
  799.           On return it will contain the actual length in
  800.           bytes of the address returned.
  801.  
  802. Error Codes                   WSANOTINITIALISED   A
  803.                               successful WSAStartup() must
  804.                               occur before using this API.
  805.           
  806.           WSAECONNREFUSED     The connection request was
  807.                               forcefully rejected as
  808.                               indicated in the return value
  809.                               of the condition function
  810.                               (CF_REJECT).
  811.           
  812.           WSAENETDOWN         The network subsystem has
  813.                               failed.
  814.           
  815.           WSAEFAULT           The addrlen argument is too
  816.                               small (less than the sizeof a
  817.                               struct sockaddr) or the
  818.                               lpfnCondition is not part of
  819.                               the user address space.
  820.           
  821.           WSAEINTR            The (blocking) call was
  822.                               canceled via
  823.                               WSACancelBlockingCall().
  824.           
  825.           WSAEINPROGRESS      A blocking Winsock call is in
  826.                               progress.
  827.           
  828.           WSAEINVAL           listen() was not invoked prior
  829.                               to WSAAccept(), parameter g
  830.                               specified in the condition
  831.                               function is not a valid value,
  832.                               the return value of the
  833.                               condition function is not a
  834.                               valid one, or any case where
  835.                               the specified socket is in an
  836.                               invalid state.
  837.           
  838.           WSAEMFILE           The queue is non-empty upon
  839.                               entry to WSAAccept() and there
  840.                               are no socket descriptors
  841.                               available.
  842.           
  843.           WSAENOBUFS          No buffer space is available.
  844.           
  845.           WSAENOTSOCK         The descriptor is not a
  846.                               socket.
  847.           
  848.           WSAEOPNOTSUPP       The referenced socket is not a
  849.                               type that supports connection-
  850.                               oriented service.
  851.           
  852.           WSATRY_AGAIN        The acceptance of the
  853.                               connection request was
  854.                               deferred as indicated in the
  855.                               return value of the condition
  856.                               function (CF_DEFER).
  857.           
  858.           WSAEWOULDBLOCK      The socket is marked as non-
  859.                               blocking and no connections
  860.                               are present to be accepted, or
  861.                               the connection request that
  862.                               was deferred has timed out or
  863.                               been withdrawn.
  864.           
  865. See Also  accept(), bind(), connect(), getsockopt(),
  866.           listen(), select(), socket(), WSAAsyncSelect(),
  867.           WSAConnect().
  868. WSAAsyncSelect()
  869. Description    Request event notification for a socket.
  870.  
  871.           #include < winsock2.h >
  872.  
  873.           int PASCAL FAR WSAAsyncSelect ( SOCKET s, HWND
  874.           hWnd,
  875.           unsigned int wMsg,  long lEvent );
  876.  
  877.           
  878.           s          A descriptor identifying the socket for
  879.                     which event notification is required.
  880.           
  881.           hWnd      A handle identifying the window which
  882.                     should receive a message when a network
  883.                     event occurs.
  884.           
  885.           wMsg      The message to be received when a
  886.                     network event occurs.
  887.           
  888.           lEvent    A bitmask which specifies a combination
  889.                     of network events in which the
  890.                     application is interested.
  891.  
  892. Remarks   This function is used to request that the Winsock2
  893.           DLL should send a message to the window hWnd
  894.           whenever it detects any of the network events
  895.           specified by the lEvent parameter.  The message
  896.           which should be sent is specified by the wMsg
  897.           parameter.  The socket for which notification is
  898.           required is identified by s.
  899.           
  900.           This function automatically sets socket s to non-
  901.           blocking mode, regardless of the value of lEvent.
  902.           See ioctlsocket() about how to set the socket back
  903.           to blocking mode.
  904.           
  905.           The lEvent parameter is constructed by or'ing any
  906.           of the values specified in the following list.
  907.  
  908.                Value      Meaning
  909.                FD_READ    Want to receive notification of
  910.                           readiness for reading
  911.                FD_WRITE   Want to receive notification of
  912.                           readiness for writing
  913.                FD_OOB     Want to receive notification of
  914.                           the arrival of out-of-band data
  915.                FD_ACCEPT  Want to receive notification of
  916.                           incoming connections
  917.                FD_CONNECT Want to receive notification of
  918.                           completed connection
  919.                FD_CLOSE   Want to receive notification of
  920.                           socket closure
  921.                FD_QOS     Want to receive notification of
  922.                           socket Quality of Service (QOS)
  923.                           changes
  924.                FD_GROUP_QOS    Want to receive notification
  925.                           of socket group Quality of
  926.                           Service (QOS) changes
  927.                
  928.  
  929.           Issuing a WSAAsyncSelect() for a socket cancels
  930.           any previous WSAAsyncSelect() or
  931.           WSACallbackSelect() for the same socket.  For
  932.           example, to receive notification for both reading
  933.           and writing, the application must call
  934.           WSAAsyncSelect() with both FD_READ and FD_WRITE,
  935.           as follows:
  936.           
  937.           rc = WSAAsyncSelect(s, hWnd, wMsg,
  938.                     FD_READ|FD_WRITE);
  939.           
  940.           It is not possible to specify different messages
  941.           for different events.  The following code will not
  942.           work; the second call will cancel the effects of
  943.           the first, and only FD_WRITE events will be
  944.           reported with message wMsg2:
  945.           
  946.           rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ);
  947.           rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE);
  948.           
  949.           To cancel all notification - i.e., to indicate
  950.           that Winsock2 should send no further messages
  951.           related to network events on the socket - lEvent
  952.           should be set to zero.
  953.           
  954.           rc = WSAAsyncSelect(s, hWnd, 0, 0);
  955.           
  956.           Although in this instance WSAAsyncSelect()
  957.           immediately disables event message posting for the
  958.           socket, it is possible that messages may be
  959.           waiting in the application's message queue.  The
  960.           application must therefore be prepared to receive
  961.           network event messages even after cancellation.
  962.           Closing a socket with closesocket() also cancels
  963.           WSAAsyncSelect() message sending, but the same
  964.           caveat about messages in the queue prior to the
  965.           closesocket() still applies.
  966.           
  967.           Since an accept()'ed socket has the same
  968.           properties as the listening socket used to accept
  969.           it, any WSAAsyncSelect() events set for the
  970.           listening socket apply to the accepted socket.
  971.           For example, if a listening socket has
  972.           WSAAsyncSelect() events FD_ACCEPT, FD_READ, and
  973.           FD_WRITE, then any socket accepted on that
  974.           listening socket will also have FD_ACCEPT,
  975.           FD_READ, and FD_WRITE events with the same wMsg
  976.           value used for messages.  If a different wMsg or
  977.           events are desired, the application should call
  978.           WSAAsyncSelect(), passing the accepted socket and
  979.           the desired new information.1
  980.           
  981.           When one of the nominated network events occurs on
  982.           the specified socket s, the application's window
  983.           hWnd receives message wMsg.  The wParam argument
  984.           identifies the socket on which a network event has
  985.           occurred.  The low word of lParam specifies the
  986.           network event that has occurred.  The high word of
  987.           lParam contains any error code.  The error code be
  988.           any error as defined in Winsock2.h.
  989.           
  990.           The error and event codes may be extracted from
  991.           the lParam using the macros WSAGETSELECTERROR and
  992.           WSAGETSELECTEVENT, defined in Winsock2.h as:
  993.           
  994.           #define WSAGETSELECTERROR(lParam)
  995.                     HIWORD(lParam)
  996.           #define WSAGETSELECTEVENT(lParam)
  997.                     LOWORD(lParam)
  998.           
  999.           The use of these macros will maximize the
  1000.           portability of the source code for the
  1001.           application.
  1002.           
  1003.           The possible network event codes which may be
  1004.           returned are as follows:
  1005.           
  1006.                Value      Meaning
  1007.                FD_READ    Socket s ready for reading
  1008.                FD_WRITE   Socket s ready for writing
  1009.                FD_OOB     Out-of-band data ready for
  1010.                           reading on socket s.
  1011.                FD_ACCEPT  Socket s ready for accepting a
  1012.                           new incoming connection
  1013.                FD_CONNECT Connection initiated on socket s
  1014.                           completed
  1015.                FD_CLOSE   Connection identified by socket s
  1016.                           has been closed
  1017.                FD_QOS     Quality of Service associated
  1018.                           with socket s has changed.
  1019.                FD_GROUP_QOS    Quality of Service
  1020.                           associated with the socket group
  1021.                to which s belongs has changed.
  1022.                
  1023.           
  1024. Return Value   The return value is 0 if the application's
  1025.           declaration of interest in the network event set
  1026.           was successful.  Otherwise the value SOCKET_ERROR
  1027.           is returned, and a specific error number may be
  1028.           retrieved by calling WSAGetLastError().
  1029.  
  1030. Comments  Although WSAAsyncSelect() can be called with
  1031.           interest in multiple events, the application
  1032.           window will receive a single message for each
  1033.           network event.
  1034.           
  1035.           As in the case of the select() function,
  1036.           WSAAsyncSelect() will frequently be used to
  1037.           determine when a data transfer operation (send()
  1038.           or recv()) can be issued with the expectation of
  1039.           immediate success.  Nevertheless, a robust
  1040.           application must be prepared for the possibility
  1041.           that it may receive a message and issue a Winsock2
  1042.           call which returns WSAEWOULDBLOCK immediately.
  1043.           For example, the following sequence of events is
  1044.           possible:
  1045.           
  1046.           (i)       data arrives on socket s; Winsock2 posts
  1047.                     WSAAsyncSelect message
  1048.           (ii)      application processes some other message
  1049.           (iii)     while processing, application issues an
  1050.                     ioctlsocket(s, FIONREAD...) and notices
  1051.                     that there is data ready to be read
  1052.           (iv)      application issues a recv(s,...) to read
  1053.                     the data
  1054.           (v)       application  loops to process next
  1055.                     message, eventually reaching the
  1056.                     WSAAsyncSelect message indicating that
  1057.                     data is ready to read
  1058.           (vi)      application issues recv(s,...), which
  1059.                     fails with the error WSAEWOULDBLOCK.
  1060.           
  1061.           Other sequences are possible.
  1062.           
  1063.           TheWinsock2 DLL will not continually flood an
  1064.           application with messages for a particular network
  1065.           event.  Having successfully posted notification of
  1066.           a particular event to an application window, no
  1067.           further message(s) for that network event will be
  1068.           posted to the application window until the
  1069.           application makes the function call which
  1070.           implicitly reenables notification of that network
  1071.           event.
  1072.  
  1073.           Event          Re-enabling function
  1074.           FD_READ        recv() or recvfrom()
  1075.           FD_WRITE       send() or sendto() or
  1076.                          WSAGetBuffer()
  1077.           FD_OOB         recv()
  1078.           FD_ACCEPT      accept() or WSAAcceptEx() unless
  1079.                          the error code returned is
  1080.                          WSATRY_AGAIN indicating that the
  1081.                          condition function returned
  1082.                          CF_DEFER
  1083.           FD_CONNECT     NONE
  1084.           FD_CLOSE       NONE
  1085.           FD_QOS         getsockopt() with option
  1086.                          SO_FLOWSPEC
  1087.           FD_GROUP_QOS   getsockopt() with option
  1088.                          SO_GROUP_FLOWSPEC
  1089.           
  1090.           Any call to the reenabling routine, even one which
  1091.           fails, results in reenabling of message posting
  1092.           for the relevant event.
  1093.           
  1094.           For FD_READ, FD_OOB, FD_ACCEPT, FD_QOS and
  1095.           FD_GROUP_QOS events, message posting is "level-
  1096.           triggered."  This means that if the reenabling
  1097.           routine is called and the relevant event is still
  1098.           valid after the call, a WSAAsyncSelect() message
  1099.           is posted to the application.  This allows an
  1100.           application to be event-driven and not be
  1101.           concerned with the amount of data that arrives at
  1102.           any one time.  Consider the following sequence:
  1103.           
  1104.           (i)       network transport stack receives 100
  1105.                     bytes of data on socket s and causes
  1106.                     Winsock2 to post an FD_READ message.
  1107.           (ii)      The application issues recv( s, buffptr,
  1108.                     50, 0) to read 50 bytes.
  1109.           (iii)     another FD_READ message is posted since
  1110.                     there is still data to be read.
  1111.           
  1112.           With these semantics, an application need not read
  1113.           all available data in response to an FD_READ
  1114.           message--a single recv() in response to each
  1115.           FD_READ message is appropriate.  If an application
  1116.           issues multiple recv() calls in response to a
  1117.           single FD_READ, it may receive multiple FD_READ
  1118.           messages.  Such an application may wish to disable
  1119.           FD_READ messages before starting the recv() calls
  1120.           by calling WSAAsyncSelect() with the FD_READ event
  1121.           not set.
  1122.           
  1123.           If an event has already happened when the
  1124.           application calls WSAAsyncSelect() or when the
  1125.           reenabling function is called, then a message is
  1126.           posted as appropriate.  All the events have
  1127.           persistence beyond the occurrence of their
  1128.           respective events.  For example, consider the
  1129.           following sequence: 1) an application calls
  1130.           listen(), 2) a connect request is received but not
  1131.           yet accepted, 3) the application calls
  1132.           WSAAsyncSelect() specifying that it wants to
  1133.           receive FD_ACCEPT messages for the socket.  Due to
  1134.           the persistence of events, Winsock2 posts an
  1135.           FD_ACCEPT message immediately.
  1136.           
  1137.           The FD_WRITE event is handled slightly
  1138.           differently.  An FD_WRITE message is posted when a
  1139.           socket is first connected with connect() or
  1140.           accepted with accept(), and then after a send() or
  1141.           sendto(), or WSAGetBuffer() fails with
  1142.           WSAEWOULDBLOCK and buffer space becomes available.
  1143.           Therefore, an application can assume that sends
  1144.           are possible starting from the first FD_WRITE
  1145.           message and lasting until a send returns
  1146.           WSAEWOULDBLOCK.  After such a failure the
  1147.           application will be notified that sends are again
  1148.           possible with an FD_WRITE message.
  1149.           
  1150.           The FD_OOB event is used only when a socket is
  1151.           configured to receive out-of-band data separately.
  1152.           If the socket is configured to receive out-of-band
  1153.           data in-line, the out-of-band (expedited) data is
  1154.           treated as normal data and the application should
  1155.           register an interest in, and will  receive,
  1156.           FD_READ events, not FD_OOB events.  An application
  1157.           may set or inspect the way in which out-of-band
  1158.           data is to be handled by using setsockopt() or
  1159.           getsockopt() for the SO_OOBINLINE option.
  1160.           
  1161.           The error code in an FD_CLOSE message indicates
  1162.           whether the socket close was graceful or abortive.
  1163.           If the error code is 0, then the close was
  1164.           graceful; if the error code is WSAECONNRESET, then
  1165.           the socket's virtual circuit was reset.  This only
  1166.           applies to connection-oriented sockets such as
  1167.           SOCK_STREAM.
  1168.           
  1169.           The FD_CLOSE message is posted when a close
  1170.           indication is received for the virtual circuit
  1171.           corresponding to the socket.  In TCP terms, this
  1172.           means that the FD_CLOSE is posted when the
  1173.           connection goes into the FIN WAIT or CLOSE WAIT
  1174.           states.  This results from the remote end
  1175.           performing a shutdown() on the send side or a
  1176.           closesocket().
  1177.           
  1178.           Please note your application will receive ONLY an
  1179.           FD_CLOSE message to indicate closure of a virtual
  1180.           circuit, and only when all the received data has
  1181.           been read if this is a graceful close. It will NOT
  1182.           receive an FD_READ message to indicate this
  1183.           condition.
  1184.           
  1185.           The FD_QOS or FD_GROUP_QOS message is posted when
  1186.           any field in the flow spec associated with socket
  1187.           s or the socket group that s belongs to has
  1188.           changed, respectively.  Applications might use
  1189.           getsocketopt() with option SO_FLOWSPEC or
  1190.           SO_GROUP_FLOWSPEC to get the current QOS for
  1191.           socket s or for the socket group s belongs to,
  1192.           respectively.
  1193.           
  1194. Error Codes                   WSANOTINITIALISED   A
  1195.                               successful WSAStartup() must
  1196.                               occur before using this API.
  1197.           
  1198.           WSAENETDOWN         The network subsystem has
  1199.                               failed.
  1200.           
  1201.           WSAEINVAL           Indicates that one of the
  1202.                               specified parameters was
  1203.                               invalid, or the specified
  1204.                               socket is in an invalid state.
  1205.           
  1206.           WSAEINPROGRESS      A blocking Winsock2 call is in
  1207.                               progress, or the service
  1208.                               provider is still processing a
  1209.                               callback function (see section
  1210.                               Error! Reference source not
  1211.                               found.).
  1212.           
  1213.           WSAENOTSOCK         The descriptor is not a
  1214.                               socket.
  1215.  
  1216.           Additional error codes may be set when an
  1217.           application window receives a message.  This error
  1218.           code is extracted from the lParam in the reply
  1219.           message using the WSAGETSELECTERROR macro.
  1220.           Possible error codes for each network event are:
  1221.           Event: FD_CONNECT
  1222.           Error Code          Meaning
  1223.           WSAEADDRINUSE       The specified address is
  1224.                               already in use.
  1225.           
  1226.           WSAEADDRNOTAVAIL    The specified address is not
  1227.                               available from the local
  1228.                               machine.
  1229.           
  1230.           WSAEAFNOSUPPORT     Addresses in the specified
  1231.                               family cannot be used with
  1232.                               this socket.
  1233.           
  1234.           WSAECONNREFUSED     The attempt to connect was
  1235.                               forcefully rejected.
  1236.           
  1237.           WSAENETUNREACH      The network can't be reached
  1238.                               from this host at this time.
  1239.           
  1240.           WSAENOBUFS          No buffer space is available.
  1241.                               The socket cannot be
  1242.                               connected.
  1243.           
  1244.           WSAETIMEDOUT        Attempt to connect timed out
  1245.                               without establishing a
  1246.                               connection
  1247.  
  1248.           Event: FD_CLOSE
  1249.           Error Code          Meaning
  1250.           WSAENETDOWN         The network subsystem has
  1251.                               failed.
  1252.           
  1253.           WSAECONNRESET       The connection was reset by
  1254.                               the remote side.
  1255.           
  1256.           WSAECONNABORTED     The connection was aborted due
  1257.                               to timeout or other failure.
  1258.           
  1259.           Event: FD_READ
  1260.           Event: FD_WRITE
  1261.           Event: FD_OOB
  1262.           Event: FD_ACCEPT
  1263.           Event: FD_QOS
  1264.           Event: FD_GROUP_QOS
  1265.           Error Code          Meaning
  1266.           WSAENETDOWN         The network subsystem has
  1267.                               failed.
  1268.           
  1269.  
  1270. See Also  select(), WSACallbackSelect()
  1271. WSAConnect()
  1272. Description    Establish a connection to a peer, create
  1273.           and/or join a socket group, and specify needed
  1274.           quality of service based on the supplied flow
  1275.           spec.
  1276.  
  1277.           #include <winsock2.h>
  1278.  
  1279.           int WSAAPI WSAConnect ( SOCKET s, const struct
  1280.           sockaddr FAR * name, int namelen, LPWSABUF
  1281.           lpCallerData, LPWSABUF lpCalleeData,
  1282.           GROUP g, LPQOS lpSFlowspec, LPQOS lpGFlowspec, int
  1283.           iGFlowspecLen );
  1284.  
  1285.           
  1286.           s          A descriptor identifying an unconnected
  1287.                     socket.
  1288.           
  1289.           name      The name of the peer to which the socket
  1290.                     is to be connected.
  1291.           
  1292.           namelen   The length of the name.
  1293.           
  1294.           lpCallerData   A pointer to the user data that is
  1295.                     to be transferred to the peer during
  1296.                     connection establishment.
  1297.           
  1298.           lpCalleeData   A pointer to the user data that is
  1299.                     to be transferred back from the peer
  1300.                     during connection establishment.
  1301.           
  1302.           g         The identifier of the socket group.
  1303.           
  1304.           lpSFlowspec    A pointer to the flow specs for
  1305.                     socket s, one for each direction.
  1306.           
  1307.           iSFlowspecLen  The length of the flow spec for
  1308.                     socket s, if s is unidirectional and
  1309.                     DSTREAM type socket.  Otherwise, this
  1310.                     parameter is ignored.
  1311.           
  1312.           lpGFlowspec    A pointer to the flow specs for the
  1313.                     socket group to be created, one for each
  1314.                     direction, if the value of parameter g
  1315.                     is SG_CONSTRAINED_GROUP.  Otherwise,
  1316.                     this parameter is ignored.
  1317.           
  1318.           iGFlowspecLen  The length of the flow spec for the
  1319.                     socket group to be created, if the value
  1320.                     of parameter g is SG_CONSTRAINED_GROUP.
  1321.                     Otherwise, this parameter is ignored.
  1322.  
  1323. Remarks   This function is used to create a connection to
  1324.           the specified destination, and to perform a number
  1325.           of other ancillary operations that occur at
  1326.           connect time as well.  For connection-oriented
  1327.           sockets (e.g., type SOCK_STREAM), an active
  1328.           connection is initiated to the foreign host using
  1329.           name (an address in the name space of the socket;
  1330.           for a detailed description, please see bind()).
  1331.           When this call completes successfully, the socket
  1332.           is ready to send/receive data.
  1333.           
  1334.           For a connectionless socket (e.g., type SOCK_
  1335.           DGRAM), the operation performed by WSAConnect() is
  1336.           merely to establish a default destination address
  1337.           so that the socket may be used on subsequent
  1338.           connection-oriented send and receive operations
  1339.           (send(), WSASend(), recv(), WSARecv()).  On
  1340.           connectionless sockets, exchange of user to user
  1341.           data is not possible and the corresponding
  1342.           parameters will be silently ignored.
  1343.           
  1344.           If the socket, s, is unbound, unique values are
  1345.           assigned to the local association by theWinsock
  1346.           provider, and the socket is marked as bound.  Note
  1347.           that if the address field of the name structure is
  1348.           all zeroes, WSAConnect() will return the error
  1349.           WSAEADDRNOTAVAIL.
  1350.           
  1351.           The application is responsible for allocating any
  1352.           memory space pointed to directly or indirectly by
  1353.           any of the parameters it specifies.  LPWSABUF and
  1354.           LPQOS are defined in winsock2.h as follows:
  1355.           
  1356.                typedef struct _WSABUF {
  1357.                     int       len;      // the length of the
  1358.           buffer
  1359.                     char FAR *     buf; // the pointer to
  1360.           the buffer
  1361.                } WSABUF, FAR * LPWSABUF;
  1362.           
  1363.                typedef enum
  1364.                {
  1365.                     GuaranteedService,
  1366.                     BestEffortService
  1367.                } GUARANTEE;
  1368.  
  1369.                typedef struct _flowparams
  1370.                {
  1371.                     int64          AverageBandwith;// In
  1372. Bytes/sec
  1373.                          int64          PeakBandwidth; // In
  1374. Bytes/sec
  1375.                          int64          BurstLength;   // In
  1376. microseconds
  1377.                     int64          Latency;       // In
  1378. microseconds
  1379.                     int64          DelayVariation;     // In
  1380. microseconds
  1381.                     GUARANTEE levelOfGuarantee;// Guaranteed
  1382. or
  1383.                                         // Best Effort
  1384.                     int32          CostOfCall;    //
  1385. Reserved for future
  1386.                                         // use, must be set
  1387. to 0
  1388.                     int32          ProviderId;    //
  1389. Provider Identifier
  1390.                     int32          SizePSP;  // Length of
  1391. provider
  1392.                                         // specific
  1393. parameters
  1394.                          UCHAR
  1395. ProviderSpecificParams[1];// provider specific
  1396. // parameters
  1397.                } FLOWPARAMS;
  1398.  
  1399.                typedef struct _QualityOfService
  1400.                {
  1401.                     FLOWPARAMS     ForwardFP;     //
  1402. Caller(Initiator) to callee
  1403.                     FLOWPARAMS     BackwardFP;    // Callee
  1404. to caller
  1405.                } QOS, FAR * LPQOS;
  1406.           
  1407.           The lpCallerData is a value parameter which
  1408.           contains any user data that is to be sent along
  1409.           with the connection request.  If lpCallerData is
  1410.           NULL, no user data will be passed to the peer. The
  1411.           lpCalleeData is a result parameter which will
  1412.           contain any user data passed back from the peer as
  1413.           part of the connection establishment.
  1414.           lpCalleeData->len initially contains the length of
  1415.           the buffer allocated by the application and
  1416.           pointed to by lpCalleeData->buf.  lpCalleeData-
  1417.           >len will be set to 0 if no user data has been
  1418.           passed back.  The lpCalleeData information will be
  1419.           valid when the connection operation is complete.
  1420.           For blocking sockets, this will be when the
  1421.           WSAConnect() function returns.  For non-blocking
  1422.           sockets, this will be after the FD_CONNECT
  1423.           notification has occurred. If lpCalleeData is
  1424.           NULL, no user data will be passed back.  The exact
  1425.           format of the user data is specific to the address
  1426.           family to which the socket belongs.
  1427.           
  1428.           Parameter g is used to indicate the appropriate
  1429.           actions on socket groups:
  1430.                if g is an existing socket group id, add s to
  1431.           this group, provided all the
  1432.           requirements set by this group is met; or
  1433.                if g = SG_UNCONSTRAINED_GROUP, create an
  1434.           unconstrained socket               group and have
  1435.           s as the first member; or
  1436.                if g = SG_CONSTRAINED_GROUP, create a
  1437.           constrained socket group and            have s as
  1438.           the first member; or
  1439.                if g = NULL, no operation is performed, and
  1440.           is equivalent to connect().
  1441.           For unconstrained groups, any set of sockets may
  1442.           be grouped together as long as they are supported
  1443.           by a single service provider and are connection-
  1444.           oriented.  A constrained socket group requires
  1445.           that connections on all grouped sockets be to the
  1446.           same host.  For newly created socket groups, the
  1447.           new group id can be retrieved by using
  1448.           getsockopt() with option SO_GROUP_ID, if this
  1449.           operation completes successfully.
  1450.           
  1451.           lpSFlowspec, and iSFlowspecLen specifies two
  1452.           blocks of memory containing the flow specs for
  1453.           socket s, one for each direction.  If either the
  1454.           associated transport provider in general or the
  1455.           specific type of socket in particular cannot honor
  1456.           the QOS request, an error will be returned as
  1457.           indicated below.  The forward or backward QOS
  1458.           values will be ignored, respectively, for any
  1459.           unidirectional sockets..  The first part of each
  1460.           memory block is struct FLOWSPEC, optionally
  1461.           followed by any service provider specific portion.
  1462.           Thus, lpSFlowspec->Flen and lpSFlowspec->Blen must
  1463.           be larger than or equal to the size of struct
  1464.           FLOWSPEC.  A NULL value for lpSFlowspec indicates
  1465.           no application supplied flow spec.
  1466.           
  1467.           lpGFlowspec, and iGFlowspecLen specifies two
  1468.           blocks of memory containing the flow specs for the
  1469.           socket group to be created, one for each
  1470.           direction, provided that the value of parameter g
  1471.           is SG_CONSTRAINED_GROUP.  Otherwise, these values
  1472.           are ignored.  The first part of each memory block
  1473.           is struct FLOWSPEC, optionally followed by any
  1474.           service provider specific portion.  Thus,
  1475.           lpGFlowspec->Flen and lpGFlowspec->Blen must be
  1476.           larger than or equal to the size of struct
  1477.           FLOWSPEC.  A NULL value for lpGFlowspec indicates
  1478.           no application-supplied group flow spec.
  1479.           
  1480. Comments  When connected sockets break (i.e. become closed
  1481.           for whatever reason), they should be discarded and
  1482.           recreated.   It is safest to assume that when
  1483.           things go awry for any reason on a connected
  1484.           socket, the application must discard and recreate
  1485.           the needed sockets in order to return  to a stable
  1486.           point.
  1487.  
  1488. Return Value   If no error occurs, WSAConnect() returns 0.
  1489.           Otherwise, it returns SOCKET_ERROR, and a specific
  1490.           error code may be retrieved by calling
  1491.           WSAGetLastError().
  1492.  
  1493.           On a blocking socket, the return value indicates
  1494.           success or failure of the connection attempt.
  1495.           
  1496.           On a non-blocking socket, if the return value is
  1497.           SOCKET_ERROR an application should call
  1498.           WSAGetLastError().  If this indicates an error
  1499.           code of WSAEWOULDBLOCK, then your application can
  1500.           either:
  1501.           
  1502.           1. Use select() to determine the completion of the
  1503.           connection request by checking if the socket is
  1504.           writeable,  or
  1505.           
  1506.           2. If your application is using WSAAsyncSelect()
  1507.           to indicate interest in connection events, then
  1508.           your application will receive an FD_CONNECT
  1509.           notification when the connect operation is
  1510.           complete.
  1511.           
  1512.           3. If your applicationis using WSAEventSelect() to
  1513.           indicate interest in connection events, then the
  1514.           associated event object will be signaled when the
  1515.           connect operation is complete.
  1516.  
  1517. Error Codes                   WSANOTINITIALISED   A
  1518.                               successful WSAStartup() must
  1519.                               occur before using this API.
  1520.           
  1521.           WSAENETDOWN         The network subsystem has
  1522.                               failed.
  1523.           
  1524.           WSAEADDRINUSE       The specified address is
  1525.                               already in use.
  1526.           
  1527.           WSAEINTR            The (blocking) call was
  1528.                               canceled via
  1529.                               WSACancelBlockingCall().
  1530.           
  1531.           WSAEINPROGRESS      A blocking Winsock call is in
  1532.                               progress, or the service
  1533.                               provider is still processing a
  1534.                               callback function (see section
  1535.                               Error! Reference source not
  1536.                               found.).
  1537.           
  1538.           WSAEADDRNOTAVAIL    The specified address is not
  1539.                               available from the local
  1540.                               machine.
  1541.           
  1542.           WSAEAFNOSUPPORT     Addresses in the specified
  1543.                               family cannot be used with
  1544.                               this socket.
  1545.           
  1546.           WSAECONNREFUSED     The attempt to connect was
  1547.                               forcefully rejected.
  1548.           
  1549.           WSAEDESTADDREQ      A destination address is
  1550.                               required.
  1551.           
  1552.           WSAEFAULT           The namelen argument is
  1553.                               incorrect, the buffer length
  1554.                               for lpCalleeData, lpSFlowspec,
  1555.                               and lpGFlowspec are too small,
  1556.                               or the buffer length for
  1557.                               lpCallerData is too large.
  1558.           
  1559.           WSAEINVAL           The socket is not already
  1560.                               bound to an address.
  1561.           
  1562.           WSAEINVAL           The socket is not already
  1563.                               bound to an address.
  1564.           
  1565.           WSAEINVAL           The parameter g specified in
  1566.                               the condition function is not
  1567.                               a valid value, or the
  1568.                               parameter s is a listening
  1569.                               socket.
  1570.           
  1571.           WSAEISCONN          The socket is already
  1572.                               connected.
  1573.           
  1574.           WSAEMFILE           No more socket descriptors are
  1575.                               available.
  1576.           
  1577.           WSAENETUNREACH      The network can't be reached
  1578.                               from this host at this time.
  1579.           
  1580.           WSAENOBUFS          No buffer space is available.
  1581.                               The socket cannot be
  1582.                               connected.
  1583.           
  1584.           WSAENOTSOCK         The descriptor is not a
  1585.                               socket.
  1586.           
  1587.           WSAEOPNOTSUPP       The flow specs specified in
  1588.                               lpSFlowspec and lpGFlowspec
  1589.                               cannot be satisfied.
  1590.           
  1591.           WSAEPROTONOSUPPORT  The lpCallerData augment is
  1592.                               not supported by the service
  1593.                               provider.
  1594.           
  1595.           WSAETIMEDOUT        Attempt to connect timed out
  1596.                               without establishing a
  1597.                               connection
  1598.           
  1599.           WSAEWOULDBLOCK      The socket is marked as non-
  1600.                               blocking and the connection
  1601.                               cannot be completed
  1602.                               immediately.  It is possible
  1603.                               to select() the socket while
  1604.                               it is connecting by
  1605.                               select()ing it for writing.
  1606.  
  1607. See Also  accept(), bind(), connect(), getsockname(),
  1608.           getsockopt(), socket(), select(),
  1609.           WSAAsyncSelect(), WSAEventSelect().
  1610. WSADuplicateSocket()
  1611. Description    Create a shared socket for a specified task.
  1612.  
  1613.           #include <winsock2.h>
  1614.  
  1615.           SOCKET WSAAPI WSADuplicateSocket ( SOCKET s,
  1616.           WSATASK hTargetTask );
  1617.           
  1618.           s          Specifies the local socket descriptor.
  1619.           
  1620.           hTargetTask    Specifies the handle of the target
  1621.                     task for which the shared socket will be
  1622.                     used.
  1623.           
  1624.  
  1625. Remarks   This function is used to enable socket sharing by
  1626.           creating a shared socket.  Shared sockets are
  1627.           created in the context of the source task by
  1628.           supplying an existing, local socket descriptor and
  1629.           a handle to the target task (which could be the
  1630.           same task as the source task) for which the
  1631.           sharedsocket will be used.  The newly created
  1632.           shared socket descriptor only has meaning within
  1633.           the context of the target task.
  1634.           
  1635.           To get the handle of the target task, it will
  1636.           generally be necessary to use some form of
  1637.           interprocess communication (IPC), which is out of
  1638.           the scope of this specification.  Since the
  1639.           created shared socket only has meaning in the
  1640.           target task, the source task must pass the value
  1641.           of the shared socket descriptor to the target
  1642.           task, again via some IPC mechanism.
  1643.  
  1644. Return Value   If no error occurs, WSADuplicateSocket()
  1645.           returns a descriptor referencing the new socket.
  1646.           Otherwise, a value of INVALID_SOCKET is returned,
  1647.           and a specific error code may be retrieved by
  1648.           calling WSAGetLastError().
  1649.  
  1650. Comments  Shared sockets may be used in all places where
  1651.           regular sockets are used and are, in fact,
  1652.           indistinguishable from them.  Shared sockets
  1653.           derived from a common regular socket or its
  1654.           derivatives share all aspects of the underlying
  1655.           common socket object with the exception of the
  1656.           notification mechanism.  Reference counting is
  1657.           employed to ensure that the underlying socket
  1658.           object is not closed until the last shared socket
  1659.           is closed.
  1660.           
  1661.           Since the collection of attributes which comprise
  1662.           a socket object's option set is shared, setting
  1663.           any socket option on a shared socket may have a
  1664.           global effect.  For example, if one task uses
  1665.           ioctlsocket() on a shared socket to set it into
  1666.           non-blocking mode, this change is visible to all
  1667.           of the shared sockets that reference the
  1668.           underlying common socket object.
  1669.           
  1670.           Each shared socket has an independent notification
  1671.           mechanism which conforms to the usual Winsock
  1672.           conventions.  Thus if two or more tasks are
  1673.           sharing an underlying socket object and each
  1674.           requests overlapped  notification via Windows
  1675.           messages when data is ready to be read, all such
  1676.           tasks will receive their stipulated message in an
  1677.           unspecified sequence.  The first task to perform a
  1678.           read will get some or all of the available data,
  1679.           the others will get what's left, if any.  In other
  1680.           words, it is completely up to tasks which share a
  1681.           socket to coordinate their access to the socket.
  1682.           
  1683.           As an aside, we note that simply invoking the
  1684.           WSADuplicateSocket() function on a socket s,
  1685.           causes s to become a shared socket which
  1686.           references an underlying socket object.
  1687.  
  1688. Error Codes                   WSANOTINITIALISED   A
  1689.                               successful WSAStartup() must
  1690.                               occur before using this API.
  1691.           
  1692.           WSAENETDOWN         The network subsystem has
  1693.                               failed.
  1694.           
  1695.           WSAEINVAL           Indicates that one of the
  1696.                               specified parameters was
  1697.                               invalid
  1698.           
  1699.           WSAEINPROGRESS      A blocking Winsock call is in
  1700.                               progress, or the service
  1701.                               provider is still processing a
  1702.                               callback function (see section
  1703.                               Error! Reference source not
  1704.                               found.).
  1705.           
  1706.           WSAEMFILE           No more socket descriptors are
  1707.                               available.
  1708.           
  1709.           WSAENOBUFS          No buffer space is available.
  1710.                               The socket cannot be created.
  1711.           
  1712.           WSAENOTSOCK         The descriptor is not a
  1713.                               socket.
  1714.  
  1715. See Also
  1716.  
  1717. WSAEnumProtocols()
  1718. Description    Retrieve information about available
  1719.           transport protocols.
  1720.  
  1721.           #include <winsock2.h>
  1722.  
  1723.           int WSAAPI WSAEnumProtocols ( LPDWORD
  1724.           lpdwProtocols, LPVOID lpProtocolBuffer, LPDWORD
  1725.           lpdwBufferLength);
  1726.           
  1727.           lpdwProtocols  a NULL-terminated array of protocol
  1728.                     ids.  This parameter is optional; if
  1729.                     lpdwProtocols is NULL, information on
  1730.                     all available protocols is returned,
  1731.                     otherwise information is retrieved only
  1732.                     for those protocols listed in the array.
  1733.           
  1734.           lpProtocolBuffer    a buffer which is filled with
  1735.                     PROTOCOL_INFO structures.  See below for
  1736.                     a detailed description of the contents
  1737.                     of the PROTOCOL_INFO structure.
  1738.           
  1739.           lpdwBufferLength    on input, the count of bytes
  1740.                     in the lpProtocolBuffer buffer passed to
  1741.                     EnumProtocols().  On output, the minimum
  1742.                     buffer size that can be passed to
  1743.                     EnumProtocols() to retrieve all the
  1744.                     requested information.  This routine has
  1745.                     no ability to enumerate over multiple
  1746.                     calls; the passed-in buffer must be
  1747.                     large enough to hold all entries in
  1748.                     order for the routine to succeed.  This
  1749.                     reduces the complexity of the API and
  1750.                     should not pose a problem because the
  1751.                     number of protocols loaded on a machine
  1752.                     is typically small
  1753.           
  1754.  
  1755. Remarks   This function is used to discover information
  1756.           about the collection of transport protocols
  1757.           installed on the local machine. The lpdwProtocols
  1758.           parameter can be used as a filter to constrain the
  1759.           amount of information provided.  Normally it will
  1760.           be supplied as a NULL pointer which will cause the
  1761.           routine to return information on all available
  1762.           transport protocols.
  1763.           
  1764.           A PROTOCOL_INFO struct is provided in the buffer
  1765.           pointed to by lpProtocolBuffer for each requested
  1766.           protocol.  If the supplied buffer is not large
  1767.           enough (as indicated by the input value of
  1768.           lpdwBufferLength ), the value pointed to by
  1769.           lpdwBufferLength  will be updated to indicate the
  1770.           required buffer size.  The application should then
  1771.           obtain a large enough buffer and call this
  1772.           function again.
  1773.           
  1774. Definitions    PROTOCOL_INFO Structure:
  1775.     DWORD dwServiceFlags1 - a bitmask describing the
  1776.         services provided by the protocol.  The following
  1777.         values are possible:
  1778.         
  1779.                 XP1_CONNECTIONLESS -the Protocol provides
  1780.                     connectionless (datagram) service.  If
  1781.                     not set, the protocol supports
  1782.                     connection-oriented data transfer.
  1783.                     
  1784.                 XP1_GUARANTEED_DELIVERY - the protocol
  1785.                     guarantees that all data sent will reach
  1786.                     the intended desitnation.
  1787.                     
  1788.                 XP1_GUARANTEED_ORDER - the protocol
  1789.                     guarantees that data will only arrive in
  1790.                     the order in which it was sent and that
  1791.                     it will not be duplicated.  This
  1792.                     characteristic does not necessarily mean
  1793.                     that the data will always be delivered,
  1794.                     but that any data that is delivered is
  1795.                     delivered in the order in which it was
  1796.                     sent.
  1797.                     
  1798.                 XP1_MESSAGE_ORIENTED - the protocol honors
  1799.                     message boundaries, as opposed to a
  1800.                     stream-oriented Protocol where there is
  1801.                     no concept of message boundaries.
  1802.                     
  1803.                 XP1_PSEUDO_STREAM - this is a message
  1804.                     oriented protocol, but message
  1805.                     boundaries will be ignored for all
  1806.                     receives.  This is convenient when an
  1807.                     application does not desire message
  1808.                     framing to be done by the protocol.
  1809.                     
  1810.                 XP1_GRACEFUL_CLOSE - the protocol supports
  1811.                     two-phase (graceful) close.  If not set,
  1812.                     only abortive closes are performed.
  1813.                     
  1814.                 XP1_EXPEDITED_DATA - the protocol supports
  1815.                     expedited (urgent) data.
  1816.                     
  1817.                 XP1_CONNECT_DATA - the protocol supports
  1818.                     connect data.
  1819.                     
  1820.                 XP1_DISCONNECT_DATA - the protocol supports
  1821.                     disconnect data.
  1822.                     
  1823.                 XP1_SUPPORTS_BROADCAST - the protocol
  1824.                     supports a broadcast mechanism.
  1825.                     
  1826.                 XP1_SUPPORTS_MULTICAST - the protocol
  1827.                     supports a multicast mechanism.
  1828.                     
  1829.                 XP1_QOS_SUPPORTED - the protocol supports
  1830.                     quality of service requests.
  1831.                     
  1832.                 XP1_ENCRYPTS - the protocol supports data
  1833.                     encryption.
  1834.                     
  1835.                 XP1_INTERRUPT - for 16 bit environments
  1836.                     (only), the protocol allows
  1837.                     send()/WSASend() and recv()/WSARecv() to
  1838.                     be invoked in interrupt context.
  1839.                     
  1840.                 XP1_UNI_SEND - the protocol is
  1841.                     unidirectional in the send direction.
  1842.                     
  1843.                 XP1_UNI_RECV - the protocol is
  1844.                     unidirectional in the recv direction.
  1845.                     
  1846.                 
  1847.                 
  1848.     DWORD dwServiceFlags2 - reserved for additional protocol
  1849.         attribute definitions
  1850.         
  1851.     DWORD dwServiceFlags3- reserved for additional protocol
  1852.         attribute definitions
  1853.         
  1854.     DWORD dwServiceFlags4 - reserved for additional protocol
  1855.         attribute definitions
  1856.         
  1857.     INT iProviderID- A unique identifier assigned to the
  1858.         underlying transport service provider at the time it
  1859.         was installed under Winsock 2.  This value is useful
  1860.         for instances where more than one service provider
  1861.         is able to implement a particular protocol.  An
  1862.         application may use the iProviderID  value to
  1863.         distinguish between providers that might otherwise
  1864.         be indistinguishable.
  1865.         
  1866.     INT  iVersion -Protocol version identifier.
  1867.         
  1868.      INT     iAddressFamily - the value to pass as the
  1869.         address family parameter to the socket() API in
  1870.         order to open a socket for this protocol.  This
  1871.         value also uniquely defines the structure of
  1872.         Protocol addresses (SOCKADDRs) used by the protocol.
  1873.         
  1874.     INT iMaxSockAddr - The maximum address length.
  1875.         
  1876.     INT iMinSockAddr - The minimum address length.
  1877.         
  1878.     INT iSocketType - The value to pass as the socket type
  1879.         parameter to the socket() API in order to open a
  1880.         socket for this protocol.
  1881.         
  1882.     INT iProtocol - The value to pass as the protocol
  1883.         parameter to the socket() API in order to open a
  1884.         socket for this protocol.
  1885.         
  1886.     BOOL bMultiple - A flag to indicate that this is one of
  1887.         two or more entries for a single protocol which is
  1888.         capable of implementing multiple behaviors.  An
  1889.         example of this is SPX which on the receiving side
  1890.         can behave either as a message oriented or a stream
  1891.         oriented protocol.
  1892.         
  1893.     BOOL bFirst - A flag to indicate that this is the prime
  1894.         or most frequently used entry for a protocol which
  1895.         is capable of implementing multiple behaviors.
  1896.         
  1897.     DWORD dwMessageSize - The maximum message size supported
  1898.         by the protocol.  This is the maximum size that can
  1899.         be sent from any of the host's local interfaces.
  1900.         For protocols which do not support message framing,
  1901.         the actual maximum that can be sent to a given
  1902.         address may be less. The following special values
  1903.         are defined:
  1904.         
  1905.                 0 - the protocol is stream-oriented and
  1906.                     hence the concept of message size is not
  1907.                     relevent.
  1908.                     
  1909.                 0x1 - the maximum message size is dependent
  1910.                     on the underlying network MTU (maximum
  1911.                     sized transmission unit) and hence
  1912.                     cannot be known until after a socket is
  1913.                     bound.  Applications should use
  1914.                     getsockopt()  to retrieve the value of
  1915.                     SO_MAX_MSG_SIZE after the socket has
  1916.                     been bound to a local address.
  1917.                     
  1918.                 0xFFFFFFFF - the protocol is message-
  1919.                     oriented, but there is no maximum limit
  1920.                     to the size of messages that may be
  1921.                     transmitted.
  1922.                     
  1923.     LPTSTR lpProtocol - a pointer to a human-readable name
  1924.         identifying the protocol, for example "SPX2".
  1925.         
  1926.     DWORD dwNameSpaces - information on which name spaces
  1927.         can be found by the transport this protocol is
  1928.         contained within.  Value encoding is TBD.
  1929.         
  1930.  
  1931.  
  1932. Return Value   If no error occurs, WSAEnumProtocols()
  1933.           returns the number of protocols to be reported on.
  1934.           Otherwise a value of TBD is returned and  a
  1935.           specific error code may be retrieved by calling
  1936.           WSAGetLastError().
  1937.  
  1938. WSAEnumNetworkEvents()
  1939. Description    Discover occurrences of network events for
  1940.           the indicated socket.
  1941.  
  1942.           #include <winsock2.h>
  1943.  
  1944.           int WSAAPI WSAEnumNetworkEvents ( SOCKET s,
  1945.           WSAEVENT hEventObject, LPWSANETWORKEVENT
  1946.           lpNetworkEvents,  LPINT lpiCount);
  1947.  
  1948.           s          A descriptor identifying the socket.
  1949.           
  1950.           hEventObject   An optional handle identifying an
  1951.                     associated event object to be reset.
  1952.           
  1953.           lpNetworkEvents     An array of WSANETWORKEVENT
  1954.                     structs, each of which records an
  1955.                     occurred network event and the
  1956.                     associated error code.
  1957.           
  1958.           lpiCount  The number of elements in the array.
  1959.                     Upon returning, this parameter indicates
  1960.                     the actual number of elements in the
  1961.                     array, or the minimum number of elememts
  1962.                     needed to retrieve all the network
  1963.                     events if the return value is
  1964.                     WSAENOBUFS.
  1965.           
  1966. Remarks   This function is used to discover  which  network
  1967.           events have occurred for the indicated socket
  1968.           since the last invocation of this function. It is
  1969.           intended for use in conjunction with
  1970.           WSAEventSelect(), which associates an event object
  1971.           with one or more network events. The socket's
  1972.           internal record of network events is copied to
  1973.           lpNetworkEvents, whereafter the internal network
  1974.           events record is cleared.  If hEventObject  is non-
  1975.           null, the indicated event object is also reset.
  1976.           The Winsock2 DLL guarantees that the operations of
  1977.           copying the network event record, clearing it and
  1978.           resetting any associated event object are atomic,
  1979.           such that the next occurrence of a nominated
  1980.           network event will cause the event object to
  1981.           become set.
  1982.           
  1983.           The following error codes may be returned along
  1984.           with the respective network event:
  1985.           Event: FD_CONNECT
  1986.           Error Code          Meaning
  1987.           WSAEADDRINUSE       The specified address is
  1988.                               already in use.
  1989.           
  1990.           WSAEADDRNOTAVAIL    The specified address is not
  1991.                               available from the local
  1992.                               machine.
  1993.           
  1994.           WSAEAFNOSUPPORT     Addresses in the specified
  1995.                               family cannot be used with
  1996.                               this socket.
  1997.           
  1998.           WSAECONNREFUSED     The attempt to connect was
  1999.                               forcefully rejected.
  2000.           
  2001.           WSAENETUNREACH      The network can't be reached
  2002.                               from this host at this time.
  2003.           
  2004.           WSAENOBUFS          No buffer space is available.
  2005.                               The socket cannot be
  2006.                               connected.
  2007.           
  2008.           WSAETIMEDOUT        Attempt to connect timed out
  2009.                               without establishing a
  2010.                               connection
  2011.  
  2012.           Event: FD_CLOSE
  2013.           Error Code          Meaning
  2014.           WSAENETDOWN         The network subsystem has
  2015.                               failed.
  2016.           
  2017.           WSAECONNRESET       The connection was reset by
  2018.                               the remote side.
  2019.           
  2020.           WSAECONNABORTED     The connection was aborted due
  2021.                               to timeout or other failure.
  2022.           
  2023.           Event: FD_READ
  2024.           Event: FD_WRITE
  2025.           Event: FD_OOB
  2026.           Event: FD_ACCEPT
  2027.           Event: FD_QOS
  2028.           Event: FD_GROUP_QOS
  2029.           Error Code          Meaning
  2030.           WSAENETDOWN         The network subsystem has
  2031.                               failed.
  2032.           
  2033.           
  2034. Return Value   The return value is 0 if the operation was
  2035.           successful.  Otherwise the value SOCKET_ERROR is
  2036.           returned, and a specific error number may be
  2037.           retrieved by calling WSAGetLastError().
  2038.  
  2039. Error Codes                   WSANOTINITIALISED   A
  2040.                               successful WSAStartup() must
  2041.                               occur before using this API.
  2042.           
  2043.           WSAENETDOWN         The network subsystem has
  2044.                               failed.
  2045.           
  2046.           WSAEINVAL           Indicates that one of the
  2047.                               specified parameters was
  2048.                               invalid
  2049.           
  2050.           WSAEINPROGRESS      A blocking Winsock call is in
  2051.                               progress, or the service
  2052.                               provider is still processing a
  2053.                               callback function (see section
  2054.                               Error! Reference source not
  2055.                               found.).
  2056.  
  2057.           WSAENOBUFS          The supplied buffer is too
  2058.                               small.
  2059.           
  2060. See Also  WSAEventSelect()
  2061.  
  2062. WSAEventSelect()
  2063. Description    Specify an event object to be associated with
  2064.           the supplied set of FD_XXX network events.
  2065.  
  2066.           #include <winsock2.h>
  2067.  
  2068.           int WSAAPI WSAEventSelect ( SOCKET s, WSAEVENT
  2069.           hEventObject, long lNetworkEvents );
  2070.  
  2071.           
  2072.           s          A descriptor identifying the socket.
  2073.           
  2074.           hEventObject   A handle identifying the event
  2075.                     object to be associated with the
  2076.                     supplied set of FD_XXX network events.
  2077.           
  2078.           lNetworkEvents A bitmask which specifies the
  2079.                     combination of FD_XXX network events in
  2080.                     which the application has interest.
  2081.           
  2082.           
  2083. Remarks   This function is used to specify an event object,
  2084.           hEventObject, to be associated with the selected
  2085.           FD_XXX network events, lNetworkEvents.  The socket
  2086.           for which an event object is specified is
  2087.           identified by s.  The event object is set  when
  2088.           any of the nominated network events occurr.
  2089.  
  2090.           WSAEventSelect() operates very similarly to
  2091.           WSAAsyncSelect(), the difference being in the
  2092.           actions taken when a nominated network event
  2093.           occurs.  Whereas WSAAsyncSelect() causes an
  2094.           application-specified Windows message to be
  2095.           posted, WSAEventSelect() sets  the associated
  2096.           event object and records the occurrence of this
  2097.           event by setting the corresponding bit in an
  2098.           internal network event record.  An application can
  2099.           use WSAWaitForMultipleEvents() or
  2100.           WSAGetOverlappedResult() to wait or poll on the
  2101.           event object, and use WSAEnumNetworkEvents() to
  2102.           retrieve the contents of the internal network
  2103.           event record and thus determine which of the
  2104.           nominated network events have occurred.
  2105.           
  2106.           This function automatically sets socket s to non-
  2107.           blocking mode, regardless of the value of
  2108.           lNetworkEvents.  See ioctlsocket() about how to
  2109.           set the socket back to blocking mode.
  2110.           
  2111.                FD_ACCEPT Want to receive notification of
  2112.                          incoming connections
  2113.                FD_CONNECT     Want to receive notification
  2114.                          of completed connection
  2115.                FD_CLOSE  Want to receive notification of
  2116.                          socket closure
  2117.           The lNetworkEvents parameter is constructed by
  2118.           or'ing any of the values specified in the
  2119.           following list.
  2120.  
  2121.                Value      Meaning
  2122.                FD_READ    Want to receive notification of
  2123.                           readiness for reading
  2124.                FD_WRITE   Want to receive notification of
  2125.                           readiness for writing
  2126.                FD_OOB     Want to receive notification of
  2127.                           the arrival of out-of-band data
  2128.                FD_ACCEPT  Want to receive notification of
  2129.                           incoming connections
  2130.                FD_CONNECT Want to receive notification of
  2131.                           completed connection
  2132.                FD_CLOSE   Want to receive notification of
  2133.                           socket closure
  2134.                FD_QOS     Want to receive notification of
  2135.                           socket Quality of Service (QOS)
  2136.                           changes
  2137.                FD_GROUP_QOS    Want to receive notification
  2138.                           of socket group Quality of
  2139.                           Service (QOS) changes
  2140.                
  2141.  
  2142.           Issuing a WSAEventSelect() for a socket cancels
  2143.           any previous WSAAsyncSelect() or WSAEventSelect()
  2144.           for the same socket and clears all bits in the
  2145.           internal network event record.  For example, to
  2146.           associate an event object with both reading and
  2147.           writing network events, the application must call
  2148.           WSAEventSelect() with both FD_READ and FD_WRITE,
  2149.           as follows:
  2150.           
  2151.           rc = WSAEventSelect(s, hEventObject,
  2152.                     FD_READ|FD_WRITE);
  2153.           
  2154.           It is not possible to specify different event
  2155.           objects for different network events.  The
  2156.           following code will not work; the second call will
  2157.           cancel the effects of the first, and only FD_WRITE
  2158.           network event will be associated with
  2159.           hEventObject2:
  2160.           
  2161.           rc = WSAEventSelect(s, hEventObject1, FD_READ);
  2162.           rc = WSAEventSelect(s, hEventObject2, FD_WRITE);
  2163.           
  2164.           To cancel the association and selection of network
  2165.           events on a socket, lNetworkEvents should be set
  2166.           to zero, in which case the hEventObject parameter
  2167.           will be ignored.
  2168.           
  2169.           rc = WSAEventSelect(s, hEventObject, 0);
  2170.           
  2171.           Closing a socket with closesocket() also cancels
  2172.           the association and selection of network events
  2173.           specified in WSAEventSelect() for the socket.  The
  2174.           application, however, still needs to call
  2175.           WSACloseEvent() to explicitly close the event
  2176.           object and free any resources.
  2177.           
  2178.           Since an accept()'ed socket has the same
  2179.           properties as the listening socket used to accept
  2180.           it, any WSAEventSelect() association and network
  2181.           events selection set for the listening socket
  2182.           apply to the accepted socket.  For example, if a
  2183.           listening socket has WSAEventSelect() association
  2184.           of hEventOject with FD_ACCEPT, FD_READ, and
  2185.           FD_WRITE, then any socket accepted on that
  2186.           listening socket will also have FD_ACCEPT,
  2187.           FD_READ, and FD_WRITE network events associated
  2188.           with the same hEventObject.  If a different
  2189.           hEventObject or network events are desired, the
  2190.           application should call WSAEventSelect(), passing
  2191.           the accepted socket and the desired new
  2192.           information.2
  2193.           
  2194.  
  2195. Return Value   The return value is 0 if the application's
  2196.           specification of the network events and the
  2197.           associated event object was successful.  Otherwise
  2198.           the value SOCKET_ERROR is returned, and a specific
  2199.           error number may be retrieved by calling
  2200.           WSAGetLastError().
  2201.  
  2202. Comments  The scenarios that an event object is signaled is
  2203.           dependent on the associated network events.  The
  2204.           scenarios for each network event are listed below:
  2205.  
  2206.           Event          Scenarios the associated event
  2207.                          object get signaled
  2208.           FD_READ        When data arrives in an emply
  2209.                          transport internal queue, or at the
  2210.                          end of the recv()/recvfrom() call
  2211.                          if there is more data to be read.
  2212.           FD_WRITE       When a socket is first connected
  2213.                          with connect() or accepted with
  2214.                          accept(), or after a send() or
  2215.                          sendto(), or WSAGetBuffer() fails
  2216.                          with WSAEWOULDBLOCK and buffer
  2217.                          space becomes available or
  2218.                          WSAGetBuffer()
  2219.           FD_OOB         The same as FD_READ, but with out-
  2220.                          of-band data.
  2221.           FD_ACCEPT      When an incoming connection request
  2222.                          arrives, or at the end of accept()
  2223.                          or WSAAcceptEx() (unless the error
  2224.                          code returned is WSATRY_AGAIN) if
  2225.                          there are more incoming connection
  2226.                          requests.
  2227.           FD_CONNECT     When the connect operation
  2228.                          completed.
  2229.           FD_CLOSE       When the remote side closes the
  2230.                          virtual circuit and the application
  2231.                          has read all bufferred data for the
  2232.                          socket.
  2233.           FD_QOS         When the socket QOS changes.
  2234.           FD_GROUP_QOS   When the group QOS changes.
  2235.           
  2236.           If an network event has already happened when the
  2237.           application calls WSAEventSelect(), then the
  2238.           associated event object get signaled as
  2239.           appropriate.
  2240.           
  2241.           As in the case of the select() and
  2242.           WSAAsyncSelect() functions, WSAEventSelect() will
  2243.           frequently be used to determine when a data
  2244.           transfer operation (send() or recv()) can be
  2245.           issued with the expectation of immediate success.
  2246.           Nevertheless, a robust application must be
  2247.           prepared for the possibility that the event object
  2248.           is set and it  issues a Winsock call which returns
  2249.           WSAEWOULDBLOCK immediately.  For example, the
  2250.           following sequence of operations is possible:
  2251.           
  2252.           (i)       data arrives on socket s; Winsock sets
  2253.                     the  WSAEventSelect event object
  2254.           (ii)      application does some other processing
  2255.           (iii)     while processing, application issues an
  2256.                     ioctlsocket(s, FIONREAD...) and notices
  2257.                     that there is data ready to be read
  2258.           (iv)      application issues a recv(s,...) to read
  2259.           the data
  2260.           (v)       application eventually waits on event
  2261.                     object specified in WSAEventSelect,
  2262.                     which returns immediately indicating
  2263.                     that data is ready to read
  2264.           (vi)      application issues recv(s,...), which
  2265.                     fails with the error WSAEWOULDBLOCK.
  2266.           
  2267.           Other sequences are possible.
  2268.           
  2269.           Having successfully recorded the occurrence of the
  2270.           network event (by setting the corresponding bit in
  2271.           the internal network event record) and signaled
  2272.           the associated event object, no further actions
  2273.           are taken for that network event until the
  2274.           application makes the function call which
  2275.           implicitly reenables the setting of that network
  2276.           event and signaling of the associated event
  2277.           object.
  2278.  
  2279.           Network Event  Re-enabling function
  2280.           FD_READ        recv() or recvfrom()
  2281.           FD_WRITE       send() or sendto() or
  2282.                          WSAGetBuffer()
  2283.           FD_OOB         recv()
  2284.           FD_ACCEPT      accept() or WSAAccept() unless the
  2285.                          error code returned is WSATRY_AGAIN
  2286.                          indicating that the condition
  2287.                          function returned CF_DEFER
  2288.           FD_CONNECT     NONE
  2289.           FD_CLOSE       NONE
  2290.           FD_QOS         getsockopt() with option
  2291.                          SO_FLOWSPEC
  2292.           FD_GROUP_QOS   getsockopt() with option
  2293.                          SO_GROUP_FLOWSPEC
  2294.           
  2295.           Any call to the reenabling routine, even one which
  2296.           fails, results in reenabling of recording  and
  2297.           setting for the relevant network event and event
  2298.           object, respectively.
  2299.           
  2300.           For FD_READ, FD_OOB, FD_ACCEPT, FD_QOS and
  2301.           FD_GROUP_QOS network events, network event
  2302.           recording and event object setting  are "level-
  2303.           triggered."  This means that if the reenabling
  2304.           routine is called and the relevant network
  2305.           condition is still valid after the call, the
  2306.           network event is recorded  and the associated
  2307.           event object is set .  This allows an application
  2308.           to be event-driven and not be concerned with the
  2309.           amount of data that arrives at any one time.
  2310.           Consider the following sequence:
  2311.           
  2312.           (i)       transport provider  receives 100 bytes
  2313.                     of data on socket s and causes Winsock2
  2314.                     DLL to record the FD_READ network event
  2315.                     and set  the associated event object.
  2316.           (ii)      The application issues recv( s, buffptr,
  2317.                     50, 0) to read 50 bytes.
  2318.           (iii)     The transport provider causes WINSOCK
  2319.                     DLL to record the FD_READ network event
  2320.                     and sets the associated event object
  2321.                     again since there is still data to be
  2322.                     read.
  2323.           
  2324.           With these semantics, an application need not read
  2325.           all available data in response to an FD_READ
  2326.           network event --a single recv() in response to
  2327.           each FD_READ network event is appropriate.  If an
  2328.           application issues multiple recv() calls in
  2329.           response to a single FD_READ, it may receive
  2330.           multiple FD_READ messages.  Such an application
  2331.           may wish to disable FD_READ messages before
  2332.           starting the recv() calls by calling
  2333.           WSAAsyncSelect() with the FD_READ event not set.
  2334.           
  2335.           If a network event has already happened when the
  2336.           application calls WSAEventSelect() or when the
  2337.           reenabling function is called, then a network
  2338.           event is recorded and the associated event object
  2339.           is set as appropriate.  All the network events
  2340.           have persistence beyond the occurrence of their
  2341.           respective events.  For example, consider the
  2342.           following sequence: 1) an application calls
  2343.           listen(), 2) a connect request is received but not
  2344.           yet accepted, 3) the application calls
  2345.           WSAEventSelect() specifying that it is interested
  2346.           in the  FD_ACCEPT network event for the socket.
  2347.           Due to the persistence of network events, Winsock
  2348.           records  the FD_ACCEPT network event and sets  the
  2349.           associated event object immediately.
  2350.           
  2351.           The FD_WRITE network event is handled slightly
  2352.           differently.  An FD_WRITE network event is
  2353.           recorded  when a socket is first connected with
  2354.           connect() or accepted with accept(), and then
  2355.           after a send() or sendto(), or WSAGetBuffer()
  2356.           fails with WSAEWOULDBLOCK and buffer space becomes
  2357.           available.  Therefore, an application can assume
  2358.           that sends are possible starting from the first
  2359.           FD_WRITE network event settting and lasting until
  2360.           a send returns WSAEWOULDBLOCK.  After such a
  2361.           failure the application will find out that sends
  2362.           are again possible when an FD_WRITE network event
  2363.           is recorded   and the associated event object is
  2364.           set .
  2365.           
  2366.           The FD_OOB network event is used only when a
  2367.           socket is configured to receive out-of-band data
  2368.           separately.  If the socket is configured to
  2369.           receive out-of-band data in-line, the out-of-band
  2370.           (expedited) data is treated as normal data and the
  2371.           application should register an interest in, and
  2372.           will get, FD_READ network event, not FD_OOB
  2373.           network event.  An application may set or inspect
  2374.           the way in which out-of-band data is to be handled
  2375.           by using setsockopt() or getsockopt() for the
  2376.           SO_OOBINLINE option.
  2377.           
  2378.           The error code in an FD_CLOSE network event
  2379.           indicates whether the socket close was graceful or
  2380.           abortive.  If the error code is 0, then the close
  2381.           was graceful; if the error code is WSAECONNRESET,
  2382.           then the socket's virtual circuit was reset.  This
  2383.           only applies to connection-oriented sockets such
  2384.           as SOCK_STREAM.
  2385.           
  2386.           The FD_CLOSE network event is recorded  when a
  2387.           close indication is received for the virtual
  2388.           circuit corresponding to the socket.  In TCP
  2389.           terms, this means that the FD_CLOSE is recorded
  2390.           when the connection goes into the FIN WAIT or
  2391.           CLOSE WAIT states.  This results from the remote
  2392.           end performing a shutdown() on the send side or a
  2393.           closesocket().
  2394.           
  2395.           Please note Winsock  will record  ONLY an FD_CLOSE
  2396.           network event to indicate closure of a virtual
  2397.           circuit. It will NOT record  an FD_READ network
  2398.           event to indicate this condition.
  2399.           
  2400.           The FD_QOS or FD_GROUP_QOS network event is
  2401.           recorded  when any field in the flow spec
  2402.           associated with socket s or the socket group that
  2403.           s belongs to has changed, respectively.
  2404.           Applications should use getsocketopt() with option
  2405.           SO_FLOWSPEC or SO_GROUP_FLOWSPEC to get the
  2406.           current QOS for socket s or for the socket group s
  2407.           belongs to, respectively.
  2408.           
  2409. Error Codes                   WSANOTINITIALISED   A
  2410.                               successful WSAStartup() must
  2411.                               occur before using this API.
  2412.           
  2413.           WSAENETDOWN         The network subsystem has
  2414.                               failed.
  2415.           
  2416.           WSAEINVAL           Indicates that one of the
  2417.                               specified parameters was
  2418.                               invalid, or the specified
  2419.                               socket is in an invalid state.
  2420.           
  2421.           WSAEINPROGRESS      A blocking Winsock call is in
  2422.                               progress, or the service
  2423.                               provider is still processing a
  2424.                               callback function (see section
  2425.                               Error! Reference source not
  2426.                               found.).
  2427.           
  2428.           WSAENOTSOCK         The descriptor is not a
  2429.                               socket.
  2430.  
  2431.  
  2432. See Also  WSACloseEvent(),WSACreateEvent(),
  2433.           WSAEnumNetworkEvents(),
  2434.           WSAGetOverlappedResult(),WSAWaitForMultipleEvents(
  2435.           ).
  2436. WSARecv()
  2437. Description    Receive data from a socket, possibly using
  2438.           overlapped I/O.
  2439.  
  2440.           #include <winsock2.h>
  2441.  
  2442.           int WSAAPI WSARecv ( SOCKET s, LPVOID lpBuffer,
  2443.           DWORD nNumberOfBytesToRecv, LPDWORD
  2444.           lpNumberOfBytesRecvd, LPINT lpFlags,
  2445.           LPWSAOVERLAPPED lpOverlapped,
  2446.           LPWSAOVERLAPPED_COMPLETION_ROUTINE
  2447.           lpCompletionRoutine );
  2448.  
  2449.           
  2450.           s               A descriptor identifying a
  2451.                          connected socket.
  2452.           
  2453.           lpBuffer       A pointer to the buffer for the
  2454.                          incoming data.
  2455.           
  2456.           nNumberOfBytesToRecv     The number of bytes to
  2457.                          receive from the network.
  2458.           
  2459.           lpNumberOfBytesRecvd     A pointer to the number
  2460.                          of bytes received by this call.
  2461.           
  2462.           lpFlags        A pointer to flags.
  2463.           
  2464.           lpOverlapped   A pointer to a WSAOVERLAPPED
  2465.                          structure (ignored for non-
  2466.                          overlapped sockets).
  2467.           
  2468.           lpCompletionRoutine A pointer to the completion
  2469.                          routine called when the receive
  2470.                          operation has been completed
  2471.                          (ignored for non-overlapped
  2472.                          sockets)..
  2473.  
  2474. Remarks   This function is used on a connection-oriented
  2475.           socket specified by s.  For overlapped sockets it
  2476.           is used  to post a buffer into which incoming data
  2477.           will be placed as it becomes available.  For non-
  2478.           overlapped sockets it behaves the same as the
  2479.           standard recv() function except that the flags
  2480.           parameter is both an input and an output
  2481.           parameter.  It can also be used on connectionless
  2482.           sockets which have a stipulated default peer
  2483.           address established via the connect() or
  2484.           WSAConnect() functions.
  2485.  
  2486.           For byte stream style sockets (e.g., type
  2487.           SOCK_STREAM), incoming data is placed into the
  2488.           buffer until the buffer is filled.  If the socket
  2489.           has been configured for in-line reception of out-
  2490.           of-band data (socket option SO_OOBINLINE) and out-
  2491.           of-band data is unread, only out-of-band data will
  2492.           be filled.  The application may use the
  2493.           ioctlsocket() SIOCATMARK to determine whether any
  2494.           more out-of-band data remains to be read.
  2495.           
  2496.           For message-oriented sockets (e.g., type
  2497.           SOCK_DGRAM), an incoming message is placed into
  2498.           the supplied buffer, up to the size of the buffer
  2499.           supplied.  If the message is larger than the
  2500.           buffer supplied, the buffer is filled with the
  2501.           first part of the message.  The MSG_PARTIAL flag
  2502.           is set for the socket,  if this feature is
  2503.           supported by the underlying protocol, and
  2504.           subsequent receive operation(s) will retrive the
  2505.           rest of the message.  Otherwise, the excess data
  2506.           is lost, and WSARecv() returns the error
  2507.           WSAEMSGSIZE.
  2508.           If no incoming data is available at the socket,
  2509.           the recv() call waits for data to arrive unless
  2510.           the socket is non-blocking.  In this case a value
  2511.           of SOCKET_ERROR is returned with the error code
  2512.           set to WSAEWOULDBLOCK.  The select(),
  2513.           WSAAsyncSelect() or WSACallbackSelect() calls may
  2514.           be used to determine when more data arrives.
  2515.           
  2516.           If the socket is connection-oriented and the
  2517.           remote side has shut down the connection
  2518.           gracefully, WSARecv() will fail with the error
  2519.           WSAEDISCON.  If the connection has been reset, a
  2520.           WSARecv() will fail with the error WSAECONNRESET.
  2521.           
  2522.           Overlapped socket I/O:
  2523.           This function may be called from within the
  2524.           completion routine of a previous WSARead(),
  2525.           WSAReadFrom(), WSASend() or WSASendTo() function.
  2526.           In Win16 environments, this function may also be
  2527.           called from within interrupt context provided that
  2528.           the XP1_INTERRUPT bit in the associated
  2529.           PROTOCOL_INFO struct is TRUE.
  2530.           
  2531.           The lpOverlapped parameter much be valid for the
  2532.           duration of the overlapped operation.  The
  2533.           WSAOVERLAPPED structure has the following form:
  2534.           
  2535.                typedef struct _WSAOVERLAPPED {
  2536.                     DWORD          Internal;      //
  2537.           reserved
  2538.                     DWORD          InternalHigh;  //
  2539.           reserved
  2540.                     DWORD          Offset;        // ignored
  2541.                     DWORD          OffsetHigh;         //
  2542.           ignored
  2543.                     WSAEVENT  hEvent;
  2544.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  2545.           
  2546.           If the lpCompletionRoutine parameter is NULL, the
  2547.           hEvent field of lpOverlapped must be a valid event
  2548.           object handle which is signaled when the
  2549.           overlapped operation completes. An application can
  2550.           use WSAWaitForMultipleEvents() or
  2551.           WSAGetOverlappedResult() to wait or poll on the
  2552.           event object.
  2553.           
  2554.           If lpCompletionRoutine is not NULL, the hEvent
  2555.           field is ignored and can be used by the
  2556.           application to pass context information to the
  2557.           completion routine.
  2558.           
  2559.           In Win16 environments, the service provider may
  2560.           invoke the application's completion routine from
  2561.           within an interrupt context.  Application
  2562.           developers should assume that this will be the
  2563.           case and restrict any calls made from within the
  2564.           completion routine to those that are safe for
  2565.           interrupt context.
  2566.           
  2567.           In Win32 environments, completion functions are
  2568.           invoked following the usual rules for overlapped
  2569.           procedure calls or APCs.  Specifically, the
  2570.           calling thread must be in an alertable wait (e.g.,
  2571.           using WSAWaitForMultipleEvents()) in order for the
  2572.           completion routine to be invoked..  If the calling
  2573.           thread is not in an alertable wait when the
  2574.           overlapped operation has been completed, the
  2575.           system queues the completion routine call until
  2576.           the thread enters an alterable wait.  The
  2577.           prototype of the completion routine is as follows:
  2578.           
  2579.                VOID CALLBACK CompletionRoutine( SOCKET s,
  2580.           DWORD dwError,      DWORD cbTransferred,
  2581.           LPWSAOVERLAPPED lpOverlapped );
  2582.           
  2583.           CompletionRoutine is a placeholder for an
  2584.           application-defined or library-defined function
  2585.           name.  dwError specifies the completion status for
  2586.           the overlapped operation as indicated by
  2587.           lpOverlapped.  cbTransferred specifies the number
  2588.           of bytes received.  This function does not return
  2589.           a value.
  2590.           
  2591.           Returning from this function allows invocation of
  2592.           another pending completion routine for this
  2593.           socket.  In Win32 environments, all waiting
  2594.           completion routines are called before the
  2595.           alterable thread's wait is satisfied with a return
  2596.           code of WSA_IO_COMPLETION.  The completion
  2597.           routines may be called in any order, not
  2598.           necessarily in the same order the overlapped
  2599.           operations are completed.  However, the posted
  2600.           buffers are guaranteed to be filled in the same
  2601.           order they are supplied
  2602.           
  2603.           lpFlags may be used to influence the behavior of
  2604.           the function invocation beyond the options
  2605.           specified for the associated socket.  That is, the
  2606.           semantics of this function are determined by the
  2607.           socket options and the lpFlags parameter.  The
  2608.           latter is constructed by or-ing any of the
  2609.           following values:
  2610.  
  2611.           Value     Meaning
  2612.           MSG_PEEK  Peek at the incoming data.  The data is
  2613.                     copied into the buffer but is not
  2614.                     removed from the input queue. {Hmmm,
  2615.                     "input queue" implies receive buffering
  2616.                     is occurring, which sort of defeats the
  2617.                     purpose of overlapped I/O.  Should this
  2618.                     be a valid flag for overlapped I/O?}
  2619.           
  2620.           MSG_OOB   Process out-of-band data (See section
  2621.                     Error! Reference source not found. for a
  2622.                     discussion of this topic.)
  2623.           
  2624.           Upon the completion of the overlapped operation,
  2625.           the lpNumberOfBytesRecvd parameter is filled with
  2626.           the number of bytes received, and, for message-
  2627.           oriented sockets, the MSG_PARTIAL bit is set in
  2628.           the lpFlags parameter if a partial message is
  2629.           received.  If a complete message is received,
  2630.           MSG_PARTIAL is cleared  in lpFlags.
  2631.  
  2632.  
  2633. Return Value   If no error occurs, WSARecv() returns the
  2634.           number of bytes received.  If the connection has
  2635.           been closed, it returns 0.  Otherwise, a value of
  2636.           SOCKET_ERROR is returned, and a specific error
  2637.           code may be retrieved by calling
  2638.           WSAGetLastError().
  2639.  
  2640.  
  2641. Error Codes                   WSANOTINITIALISED   A
  2642.                               successful WSAStartup() must
  2643.                               occur before using this API.
  2644.           
  2645.           WSAENETDOWN         The network subsystem has
  2646.                               failed.
  2647.           
  2648.           WSAENOTCONN         The socket is not connected.
  2649.           
  2650.           WSAEINTR            The (blocking) call was
  2651.                               canceled via
  2652.                               WSACancelBlockingCall().
  2653.           
  2654.           WSAEINPROGRESS      A blocking PII operation is in
  2655.                               progress.
  2656.  
  2657.           WSAENETRESET        The connection must be reset
  2658.                               because the service provider
  2659.                               dropped it.
  2660.           
  2661.           WSAENOTSOCK         The descriptor is not a
  2662.                               socket.
  2663.           
  2664.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  2665.                               socket is not stream style
  2666.                               such as type SOCK_STREAM, out-
  2667.                               of-band data is not supported
  2668.                               in the communication domain
  2669.                               associated with this socket,
  2670.                               or the socket is
  2671.                               unidirectional and supports
  2672.                               only send operations.
  2673.           
  2674.           WSAESHUTDOWN        The socket has been shutdown;
  2675.                               it is not possible to
  2676.                               WSARecv() on a socket after
  2677.                               shutdown() has been invoked
  2678.                               with how set to SD_RECEIVE or
  2679.                               SD_BOTH.
  2680.           
  2681.           WSAEWOULDBLOCK      Overlapped sockets: There are
  2682.                               too many outstanding
  2683.                               overlapped I/O requests.  Non-
  2684.                               overlapped sockets: The socket
  2685.                               is marked as non-blocking and
  2686.                               the receive operation cannot
  2687.                               be completed immediately.
  2688.           
  2689.           WSAEMSGSIZE         The message was too large to
  2690.                               fit into the specified buffer
  2691.                               and was truncated.
  2692.           
  2693.           WSAEINVAL           The socket has not been bound
  2694.                               with bind(), or the socket is
  2695.                               not created with the
  2696.                               overlapped flag.
  2697.           
  2698.           WSAECONNABORTED     The virtual circuit was
  2699.                               aborted due to timeout or
  2700.                               other failure.
  2701.           
  2702.           WSAECONNRESET       The virtual circuit was reset
  2703.                               by the remote side.
  2704.           
  2705.           WSAEDISCON          The remote side gracefully
  2706.                               close the connection.
  2707.  
  2708. See Also  WSACloseEvent(),WSACreateEvent(),
  2709.           WSAGetOverlappedResult(), WSASocket(),
  2710.           WSAWaitForMultipleEvents()
  2711. WSARecvfrom()
  2712. Description    Receive a datagram and store the source
  2713.           address, possibly using overlapped I/O.
  2714.  
  2715.           #include <winsock2.h>
  2716.  
  2717.           int WSAAPI WSARecvfrom ( SOCKET s, LPVOID
  2718.           lpBuffer, DWORD nNumberOfBytesToRecv, LPDWORD
  2719.           lpNumberOfBytesRecvd, LPINT lpFlags, LPVOID
  2720.           lpFrom, LPINT lpFromlen, LPWSAOVERLAPPED
  2721.           lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
  2722.           lpCompletionRoutine );
  2723.  
  2724.           
  2725.           s               A descriptor identifying a socket
  2726.           
  2727.           lpBuffer       A pointer to the buffer for the
  2728.                          incoming data.
  2729.           
  2730.           nNumberOfBytesToRecv     The number of bytes to
  2731.                          receive from the network.
  2732.           
  2733.           lpNumberOfBytesRecvd     A pointer to the number
  2734.                          of bytes received by this call.
  2735.           
  2736.           lpFlags        A pointer to flags.
  2737.           
  2738.           lpFrom         An optional pointer to a buffer
  2739.                          which will hold the source address
  2740.                          upon the completion of the
  2741.                          overlapped operation.
  2742.           
  2743.           lpFromlen      An optional pointer to the size of
  2744.                          the from buffer.
  2745.           
  2746.           lpOverlapped   A pointer to a WSAOVERLAPPED
  2747.                          structure (ignored for non-
  2748.                          overlapped sockets)..
  2749.           
  2750.           lpCompletionRoutine A pointer to the completion
  2751.                          routine called when the receive
  2752.                          operation has been completed
  2753.                          (ignored for non-overlapped
  2754.                          sockets)..
  2755.  
  2756. Remarks   For overlapped sockets, this function is used to
  2757.           post a buffer into which incoming data will be
  2758.           placed as it becomes available on a (possibly
  2759.           connected) socket. The data must have already been
  2760.           received by the transport for non-overlapped
  2761.           sockets.
  2762.  
  2763.           For connectionless socket types, the address from
  2764.           which the data originated is copied to the buffer
  2765.           pointed by lpFrom.  The value pointed to by
  2766.           lpFromlen is initialized to the size of this
  2767.           buffer, and is modified on return to indicate the
  2768.           actual size of the address stored there. The
  2769.           lpFrom and lpFromlen parameters are ignored for
  2770.           connection-oriented sockets.
  2771.  
  2772.           For byte stream style sockets (e.g., type
  2773.           SOCK_STREAM), incoming data is placed into the
  2774.           buffer until the buffer is filled. For message-
  2775.           oriented sockets, an incoming message is placed
  2776.           into the supplied buffer, up to the size of the
  2777.           buffer supplied.  If the message is larger than
  2778.           the buffer supplied, the buffer is filled with the
  2779.           first part of the message.  The MSG_PARTIAL flag
  2780.           is set for the socket,  if this feature is
  2781.           supported by the underlying protocol, and
  2782.           subsequent receive operation(s) will retrive the
  2783.           rest of the message.  Otherwise, the excess data
  2784.           is lost, and WSARecvfrom() returns the error code
  2785.           WSAEMSGSIZE.
  2786.           
  2787.           If no incoming data is available at the socket,
  2788.           the recvfrom() call waits for data to arrive
  2789.           unless the socket is non-blocking.  In this case a
  2790.           value of SOCKET_ERROR is returned with the error
  2791.           code set to WSAEWOULDBLOCK.  The select(),
  2792.           WSAAsyncSelect() or WSACallbackSelect() may be
  2793.           used to determine when more data arrives.
  2794.           
  2795.           If the socket is connection-oriented and the
  2796.           remote side has shut down the connection
  2797.           gracefully, a WSARecvfrom() will fail with the
  2798.           error WSAEDISCON.  If the connection has been
  2799.           reset WSARecvfrom() will fail with the error
  2800.           WSAECONNRESET.
  2801.           
  2802.           Overlapped socket I/O:
  2803.           This function may be called from within the
  2804.           completion routine of a previous WSARead(),
  2805.           WSAReadFrom(), WSASend() or WSASendTo() function.
  2806.           In Win16 environments, this function may also be
  2807.           called from within interrupt context provided that
  2808.           the XP1_INTERRUPT bit in tthe associated
  2809.           PROTOCOL_INFO struct is TRUE.
  2810.           
  2811.           The lpOverlapped parameter much be valid for the
  2812.           duration of the overlapped operation.  The
  2813.           WSAOVERLAPPED structure has the following form:
  2814.           
  2815.                typedef struct _WSAOVERLAPPED {
  2816.                     DWORD          Internal;      //
  2817.           reserved
  2818.                     DWORD          InternalHigh;  //
  2819.           reserved
  2820.                     DWORD          Offset;        // ignored
  2821.                     DWORD          OffsetHigh;         //
  2822.           ignored
  2823.                     WSAEVENT  hEvent;
  2824.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  2825.           
  2826.           If the lpCompletionRoutine parameter is NULL, the
  2827.           hEvent field of lpOverlapped must be an event
  2828.           object handle which is signaled when the
  2829.           overlapped operation completes. An application can
  2830.           use WSAWaitForMultipleEvents() or
  2831.           WSAGetOverlappedResult() to wait or poll on the
  2832.           event object.
  2833.           
  2834.           If lpCompletionRoutine is not NULL, the hEvent
  2835.           field is ignored and can be used by the
  2836.           application to pass context information to the
  2837.           completion routine.
  2838.           
  2839.           In Win16 environments, the service provider may
  2840.           invoke the application's completion routine from
  2841.           within an interrupt context.  Application
  2842.           developers should assume that this will be the
  2843.           case and restrict any calls made from within the
  2844.           completion routine to those that are safe for
  2845.           interrupt context.
  2846.           
  2847.           In Win32 environments, completion functions are
  2848.           invoked following the usual rules for asynchronous
  2849.           procedure calls or APCs.  Specifically, the
  2850.           calling thread must be in an alertable wait (e.g.,
  2851.           using WSAWaitForMultipleEvents()) in order for the
  2852.           completion routine to be invoked..  If the calling
  2853.           thread is not in an alertable wait when the
  2854.           overlapped operation has been completed, the
  2855.           system queues the completion routine call until
  2856.           the thread enters an alterable wait.  The
  2857.           prototype of the completion routine is as follows:
  2858.           
  2859.                VOID CALLBACK CompletionRoutine( SOCKET s,
  2860.           DWORD dwError,      DWORD cbTransferred,
  2861.           LPWSAOVERLAPPED lpOverlapped );
  2862.           
  2863.           CompletionRoutine is a placeholder for an
  2864.           application-defined or library-defined function
  2865.           name.  dwError specifies the completion status for
  2866.           the overlapped operation as indicated by
  2867.           lpOverlapped.  cbTransferred specifies the number
  2868.           of bytes received.  This function does not return
  2869.           a value.
  2870.           
  2871.           Returning from this function allows invocation of
  2872.           another pending completion routine for this
  2873.           socket.  In Win32 environments, all waiting
  2874.           completion routines are called before the
  2875.           alterable thread's wait is satisfied with a return
  2876.           code of WSA_IO_COMPLETION.  The completion
  2877.           routines may be called in any order, not
  2878.           necessarily in the same order the overlapped
  2879.           operations are completed.  However, the posted
  2880.           buffers are guaranteed to be filled in the same
  2881.           order they are supplied
  2882.           
  2883.           Flags may be used to influence the behavior of the
  2884.           function invocation beyond the options specified
  2885.           for the associated socket.  That is, the semantics
  2886.           of this function are determined by the socket
  2887.           options and the flags parameter.  The latter is
  2888.           constructed by or-ing any of the following values:
  2889.  
  2890.           Value     Meaning
  2891.           MSG_PEEK  Peek at the incoming data.  The data is
  2892.                     copied into the buffer but is not
  2893.                     removed from the input queue.
  2894.           
  2895.           MSG_OOB   Process out-of-band data (See section
  2896.                     Error! Reference source not found. for a
  2897.                     discussion of this topic.)
  2898.           
  2899.           Upon the completion of the overlapped operation,
  2900.           the lpNumberOfBytesRecvd parameter is filled with
  2901.           the number of bytes received, and, for message-
  2902.           oriented sockets, the MSG_PARTIAL bit is set in
  2903.           the lpFlags parameter if a partial message is
  2904.           received.  If a complete message is received,
  2905.           MSG_PARTIAL is cleared  in lpFlags.
  2906.           
  2907.  
  2908. Return Value   If no error occurs, WSARecvfrom() returns the
  2909.           number of bytes received.  If the connection has
  2910.           been closed, it returns0.  Otherwise, a value of
  2911.           SOCKET_ERROR is returned, and a specific error
  2912.           code may be retrieved by calling
  2913.           WSAGetLastError().
  2914.  
  2915. Error Codes                   WSANOTINITIALISED   A
  2916.                               successful WSAStartup() must
  2917.                               occur before using this API.
  2918.           
  2919.           WSAENETDOWN         The network subsystem has
  2920.                               failed.
  2921.           
  2922.           WSAEFAULT           The lpFromlen argument was
  2923.                               invalid: the lpFrom buffer was
  2924.                               too small to accommodate the
  2925.                               peer address.
  2926.           
  2927.           WSAEINTR            The (blocking) call was
  2928.                               canceled via
  2929.                               WSACancelBlockingCall().
  2930.           
  2931.           WSAEINPROGRESS      A blocking PII operation is in
  2932.                               progress.
  2933.  
  2934.           WSAEINVAL           The socket has not been bound
  2935.                               with bind(), or the socket is
  2936.                               not created with the
  2937.                               overlapped flag.
  2938.           
  2939.           WSAENETRESET        The connection must be reset
  2940.                               because the Winsock provider
  2941.                               dropped it.
  2942.           
  2943.           WSAENOTCONN         The socket is not connected
  2944.                               (connection-oriented sockets
  2945.                               only).
  2946.           
  2947.           WSAENOTSOCK         The descriptor is not a
  2948.                               socket.
  2949.           
  2950.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  2951.                               socket is not stream style
  2952.                               such as type SOCK_STREAM, out-
  2953.                               of-band data is not supported
  2954.                               in the communication domain
  2955.                               associated with this socket,
  2956.                               or the socket is
  2957.                               unidirectional and supports
  2958.                               only send operations.
  2959.           
  2960.           WSAESHUTDOWN        The socket has been shutdown;
  2961.                               it is not possible to
  2962.                               WSARecvfrom() on a socket
  2963.                               after shutdown() has been
  2964.                               invoked with how set to
  2965.                               SD_RECEIVE or SD_BOTH.
  2966.           
  2967.           WSAEWOULDBLOCK      Overlapped sockets: There are
  2968.                               too many outstanding
  2969.                               overlapped I/O requests. .
  2970.                               Non-overlapped sockets: The
  2971.                               socket is marked as non-
  2972.                               blocking and the receive
  2973.                               operation cannot be completed
  2974.                               immediately.
  2975.           
  2976.           WSAEMSGSIZE         The message was too large to
  2977.                               fit into the specified buffer
  2978.                               and was truncated.
  2979.           
  2980.           WSAECONNABORTED     The virtual circuit was
  2981.                               aborted due to timeout or
  2982.                               other failure.
  2983.           
  2984.           WSAECONNRESET       The virtual circuit was reset
  2985.                               by the remote side.
  2986.           
  2987.           WSAEDISCON          The remote side gracefully
  2988.                               close the connection.
  2989.           
  2990.           
  2991. See Also  WSACloseEvent(),WSACreateEvent(),
  2992.           WSAGetOverlappedResult(), WSASocket(),
  2993.           WSAWaitForMultipleEvents()
  2994.  
  2995.  
  2996. WSASend()
  2997. Description    Send data on a connected socket using
  2998.           overlapped I/O.
  2999.  
  3000.           #include <winsock2.h>
  3001.  
  3002.           int WSAAPI WSASend ( SOCKET s, LPVOID lpBuffer,
  3003.           DWORD nNumberOfBytesToSend, LPDWORD
  3004.           lpNumberOfBytesSent, int iFlags, LPWSAOVERLAPPED
  3005.           lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
  3006.           lpCompletionRoutine );
  3007.  
  3008.           
  3009.           s               A descriptor identifying a
  3010.                          connected socket which was created
  3011.                          using WSASocket() with flag
  3012.                          WSA_FLAG_OVERLAPPED.
  3013.           
  3014.           lpBuffer       A pointer to the buffer for the
  3015.                          outgoing data.
  3016.           
  3017.           nNumberOfBytesToSend     The number of bytes to
  3018.                          send to the network.
  3019.           
  3020.           lpNumberOfBytesSent A pointer to the number of
  3021.                          bytes sent by this call.
  3022.           
  3023.           iFlags         Flags.
  3024.           
  3025.           lpOverlapped   A pointer to a WSAOVERLAPPED
  3026.                          structure.
  3027.           
  3028.           lpCompletionRoutine A pointer to the completion
  3029.                          routine called when the send
  3030.                          operation has been.
  3031.  
  3032. Remarks   WSASend() is used  to write outgoing data on a
  3033.           connected socket asynchronously.  For message-
  3034.           oriented sockets, care must be taken not to exceed
  3035.           the maximum message size of the underlying
  3036.           provider, which can be obtained by getting the
  3037.           value of socket option SO_MAX_MSG_SIZE.  If the
  3038.           data is too long to pass atomically through the
  3039.           underlying protocol the error WSAEMSGSIZE is
  3040.           returned, and no data is transmitted.
  3041.  
  3042.           Note that the successful completion of a WSASend()
  3043.           does not indicate that the data was successfully
  3044.           delivered. Upon completion of the overlapped
  3045.           operation, the value pointed to by the
  3046.           lpNumberOfBytesSent parameter is updated with the
  3047.           number of bytes sent.
  3048.           
  3049.           If no buffer space is available within the
  3050.           transport system to hold the data to be
  3051.           transmitted, send() will block unless the socket
  3052.           has been placed in a non-blocking I/O mode.  On
  3053.           non-blocking stream-oriented sockets, the number
  3054.           of bytes written may be between 1 and the
  3055.           requested length, depending on buffer availability
  3056.           on both the local and foreign hosts.  The
  3057.           select(), WSAAsyncSelect() or WSACallbackSelect()
  3058.           call may be used to determine when it is possible
  3059.           to send more data.
  3060.           
  3061.           This function may be called from within the
  3062.           completion routine of a previous WSARead(),
  3063.           WSAReadFrom(), WSASend() or WSASendTo() function.
  3064.           In Win16 environments, this function may also be
  3065.           called from within interrupt context provided that
  3066.           the XP1_INTERRUPT bit in the socket's
  3067.           PROTOCOL_INFO struct is TRUE.
  3068.           
  3069.           The lpOverlapped parameter much be valid for the
  3070.           duration of the overlapped operation.  The
  3071.           WSAOVERLAPPED structure has the following form:
  3072.           
  3073.                typedef struct _WSAOVERLAPPED {
  3074.                     DWORD          Internal;      //
  3075.           reserved
  3076.                     DWORD          InternalHigh;  //
  3077.           reserved
  3078.                     DWORD          Offset;        // ignored
  3079.                     DWORD          OffsetHigh;         //
  3080.           ignored
  3081.                     WSAEVENT  hEvent;
  3082.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  3083.           
  3084.           If the lpCompletionRoutine parameter is NULL, the
  3085.           hEvent field of lpOverlapped must be a valid event
  3086.           object handle which is signaled when the
  3087.           overlapped operation completes. An application can
  3088.           use WSAWaitForMultipleEvents() or
  3089.           WSAGetOverlappedResult() to wait or poll on the
  3090.           event object.
  3091.           
  3092.           If lpCompletionRoutine is not NULL, the hEvent
  3093.           field is ignored and can be used by the
  3094.           application to pass context information to the
  3095.           completion routine.
  3096.           
  3097.           In Win16 environments, the service provider may
  3098.           invoke the application's completion routine from
  3099.           within an interrupt context.  Application
  3100.           developers should assume that this will be the
  3101.           case and restrict any calls made from within the
  3102.           completion routine to those that are safe for
  3103.           interrupt context.
  3104.           
  3105.           In Win32 environments, completion functions are
  3106.           invoked following the usual rules for asynchronous
  3107.           procedure calls or APCs.  Specifically, the
  3108.           calling thread must be in an alertable wait (e.g.,
  3109.           using WSAWaitForMultipleEvents()) in order for the
  3110.           completion routine to be invoked..  If the calling
  3111.           thread is not in an alertable wait when the
  3112.           overlapped operation has been completed, the
  3113.           system queues the completion routine call until
  3114.           the thread enters an alterable wait.  The
  3115.           prototype of the completion routine is as follows:
  3116.           
  3117.                VOID CALLBACK CompletionRoutine( SOCKET s,
  3118.           DWORD dwError,      DWORD cbTransferred,
  3119.           LPWSAOVERLAPPED lpOverlapped );
  3120.           
  3121.           CompletionRoutine is a placeholder for an
  3122.           application-defined or library-defined function
  3123.           name.  dwError specifies the completion status for
  3124.           the overlapped operation as indicated by
  3125.           lpOverlapped.  cbTransferred specifies the number
  3126.           of bytes sent.  This function does not return a
  3127.           value.
  3128.           
  3129.           Returning from this function allows invocation of
  3130.           another pending completion routine for this
  3131.           socket.  In Win32 environments, all waiting
  3132.           completion routines are called before the
  3133.           alterable thread's wait is satisfied with a return
  3134.           code of WSA_IO_COMPLETION.  The completion
  3135.           routines may be called in any order, not
  3136.           necessarily in the same order the overlapped
  3137.           operations are completed.  However, the posted
  3138.           buffers are guaranteed to be sent in the same
  3139.           order they are supplied
  3140.           
  3141.           , s is in non-blocking mode, and the MSG_INTERRUPT
  3142.           flag is set.  Note that the meaning of the return
  3143.           value in this case is changed.
  3144.           
  3145.           Flags may be used to influence the behavior of the
  3146.           function invocation beyond the options specified
  3147.           for the associated socket.  That is, the semantics
  3148.           of this function are determined by the socket
  3149.           options and the flags parameter.  The latter is
  3150.           constructed by or-ing any of the following values:
  3151.  
  3152.           Value     Meaning
  3153.           MSG_DONTROUTE
  3154.                     Specifies that the data should not be
  3155.                     subject to routing.  A Winsock service
  3156.                     provider may choose to ignore this flag;
  3157.                     see also the discussion of the
  3158.                     SO_DONTROUTE option in section Error!
  3159.                     Reference source not found..
  3160.           
  3161.           MSG_OOB   Send out-of-band data (stream style
  3162.                     socket such as SOCK_STREAM only; see
  3163.                     also section Error! Reference source not
  3164.                     found.)
  3165.           
  3166.           MSG_PARTIAL    Specifies that lpBuffer only
  3167.                     contains a partial message.  Note that
  3168.                     this flag will be ignored by transports
  3169.                     which do not support partial message
  3170.                     transmissions.
  3171.           
  3172.           
  3173.           MSG_INTERRUPT
  3174.                     Specifies that this function is being
  3175.                     called in interrupt context.
  3176.           
  3177.  
  3178. Return Value   If no error occurs, WSASend() returns 0. the
  3179.           total number of characters sent.  (Note that this
  3180.           may be less than the number indicated by len.)
  3181.           Otherwise, a value of SOCKET_ERROR is returned,
  3182.           and a specific error code may be retrieved by
  3183.           calling WSAGetLastError().
  3184.  
  3185. Error Codes                   WSANOTINITIALISED   A
  3186.                               successful WSAStartup() must
  3187.                               occur before using this API.
  3188.           
  3189.           WSAENETDOWN         The network subsystem has
  3190.                               failed.
  3191.           
  3192.           WSAEACCES           The requested address is a
  3193.                               broadcast address, but the
  3194.                               appropriate flag was not set.
  3195.           
  3196.           WSAEINTR            The (blocking) call was
  3197.                               canceled via
  3198.                               WSACancelBlockingCall().
  3199.           
  3200.           WSAEINPROGRESS      A blocking PII operation is in
  3201.                               progress.
  3202.           
  3203.           WSAEFAULT           The lpBuffer argument is not
  3204.                               in a valid part of the user
  3205.                               address space.
  3206.           
  3207.           WSAENETRESET        The connection must be reset
  3208.                               because the Winsock provider
  3209.                               dropped it.
  3210.           
  3211.           WSAENOBUFS          The Winsock provider reports a
  3212.                               buffer deadlock.
  3213.           
  3214.           WSAENOTCONN         The socket is not connected.
  3215.           
  3216.           WSAENOTSOCK         The descriptor is not a
  3217.                               socket.
  3218.           
  3219.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  3220.                               socket is not stream style
  3221.                               such as type SOCK_STREAM, out-
  3222.                               of-band data is not supported
  3223.                               in the communication domain
  3224.                               associated with this socket,
  3225.                               or the socket is
  3226.                               unidirectional and supports
  3227.                               only receive operations.
  3228.           
  3229.           WSAESHUTDOWN        The socket has been shutdown;
  3230.                               it is not possible to
  3231.                               WSASend() on a socket after
  3232.                               shutdown() has been invoked
  3233.                               with how set to SD_SEND or
  3234.                               SD_BOTH.
  3235.           
  3236.           WSAEWOULDBLOCK      There are too many outstanding
  3237.                               overlapped I/O requests.
  3238.           
  3239.           WSAEMSGSIZE         The socket is message-
  3240.                               oriented, and the message is
  3241.                               larger than the maximum
  3242.                               supported by the underlying
  3243.                               transport.
  3244.           
  3245.           WSAEINVAL           The socket has not been bound
  3246.                               with bind(), or the socket is
  3247.                               not created with the
  3248.                               overlapped flag.
  3249.           
  3250.           WSAECONNABORTED     The virtual circuit was
  3251.                               aborted due to timeout or
  3252.                               other failure.
  3253.           
  3254.           WSAECONNRESET       The virtual circuit was reset
  3255.                               by the remote side.
  3256.           
  3257.  
  3258. See Also  WSACloseEvent(),WSACreateEvent(),
  3259.           WSAGetOverlappedResult(), WSASocket(),
  3260.           WSAWaitForMultipleEvents()
  3261.  
  3262. WSASendto()
  3263. Description    Send data to a specific destination using
  3264.           overlapped I/O.
  3265.  
  3266.           #include <winsock2.h>
  3267.  
  3268.           int WSAAPI WSASendto ( SOCKET s, LPVOID lpBuffer,
  3269.           DWORD nNumberOfBytesToSend, LPDWORD
  3270.           lpNumberOfBytesSent, int iFlags, LPVOID lpTo, int
  3271.           iTolen, LPWSAOVERLAPPED lpOverlapped,
  3272.           LPWSAOVERLAPPED_COMPLETION_ROUTINE
  3273.           lpCompletionRoutine );
  3274.  
  3275.           
  3276.           s               A descriptor identifying a
  3277.                          connected socket which was created
  3278.                          using WSASocket() with flag
  3279.                          WSA_FLAG_OVERLAPPED.
  3280.           
  3281.           lpBuffer       A pointer to the buffer for the
  3282.                          outgoing data.
  3283.           
  3284.           nNumberOfBytesToSend     The number of bytes to
  3285.                          send to the network.
  3286.           
  3287.           lpNumberOfBytesSent A pointer to the number of
  3288.                          bytes sent by this call.
  3289.           
  3290.           iFlags         Flags.
  3291.           
  3292.           lpTo           An optional pointer to the address
  3293.                          of the target socket.
  3294.           
  3295.           iTolen         The size of the address in lpTo.
  3296.           
  3297.           lpOverlapped   A pointer to a WSAOVERLAPPED
  3298.                          structure.
  3299.           
  3300.           lpCompletionRoutine A pointer to the completion
  3301.                          routine called when the send
  3302.                          operation has been completed.
  3303.  
  3304. Remarks   WSASendto() is used to write outgoing data on a
  3305.           socket asynchronously.  For message-oriented
  3306.           sockets, care must be taken not to exceed the
  3307.           maximum message size of the underlying transport,
  3308.           which can be obtained by getting the value of
  3309.           socket option SO_MAX_MSG_SIZE.  If the data is too
  3310.           long to pass atomically through the underlying
  3311.           protocol the error WSAEMSGSIZE is returned, and no
  3312.           data is transmitted.
  3313.  
  3314.           Note that the successful completion of a
  3315.           WSASendto() does not indicate that the data was
  3316.           successfully delivered. Upon completion of the
  3317.           overlapped operation, the value pointed to by the
  3318.           lpNumberOfBytesSent parameter is updated with the
  3319.           number of bytes sent.
  3320.           
  3321.           WSASendto() is normally used on a connectionless
  3322.           socket to send a datagram to a specific peer
  3323.           socket identified by the lpTo parameter.  On a
  3324.           connection-oriented socket, the lpTo and iTolen
  3325.           parameters are ignored; in this case the
  3326.           WSASendto() is equivalent to WSASend().
  3327.           
  3328.           This function may be called from within the
  3329.           completion routine of a previous WSARead(),
  3330.           WSAReadFrom(), WSASend() or WSASendTo() function.
  3331.           In Win16 environments, this function may also be
  3332.           called from within interrupt context provided that
  3333.           the XP1_INTERRUPT bit in the socket's
  3334.           PROTOCOL_INFO struct is TRUE.
  3335.           
  3336.           The lpOverlapped parameter much be valid for the
  3337.           duration of the overlapped operation.  The
  3338.           WSAOVERLAPPED structure has the following form:
  3339.           
  3340.                typedef struct _WSAOVERLAPPED {
  3341.                     DWORD          Internal;      //
  3342.           reserved
  3343.                     DWORD          InternalHigh;  //
  3344.           reserved
  3345.                     DWORD          Offset;        // ignored
  3346.                     DWORD          OffsetHigh;         //
  3347.           ignored
  3348.                     WSAEVENT  hEvent;
  3349.                } WSAOVERLAPPED, LPWSAOVERLAPPED;
  3350.           
  3351.           If the lpCompletionRoutine parameter is NULL, the
  3352.           hEvent field of lpOverlapped must be an event
  3353.           object handle which is signaled when the
  3354.           overlapped operation completes. An application can
  3355.           use WSAWaitForMultipleEvents() or
  3356.           WSAGetOverlappedResult() to wait or poll on the
  3357.           event object.
  3358.           
  3359.           If lpCompletionRoutine is not NULL, the hEvent
  3360.           field is ignored and can be used by the
  3361.           application to pass context information to the
  3362.           completion routine.
  3363.           
  3364.           In Win16 environments, the service provider may
  3365.           invoke the application's completion routine from
  3366.           within an interrupt context.  Application
  3367.           developers should assume that this will be the
  3368.           case and restrict any calls made from within the
  3369.           completion routine to those that are safe for
  3370.           interrupt context.
  3371.           
  3372.           In Win32 environments, completion functions are
  3373.           invoked following the usual rules for asynchronous
  3374.           procedure calls or APCs.  Specifically, the
  3375.           calling thread must be in an alertable wait (e.g.,
  3376.           using WSAWaitForMultipleEvents()) in order for the
  3377.           completion routine to be invoked..  If the calling
  3378.           thread is not in an alertable wait when the
  3379.           overlapped operation has been completed, the
  3380.           system queues the completion routine call until
  3381.           the thread enters an alterable wait.  The
  3382.           prototype of the completion routine is as follows:
  3383.           
  3384.                VOID CALLBACK CompletionRoutine( SOCKET s,
  3385.           DWORD dwError,      DWORD cbTransferred,
  3386.           LPWSAOVERLAPPED lpOverlapped );
  3387.           
  3388.           CompletionRoutine is a placeholder for an
  3389.           application-defined or library-defined function
  3390.           name.  dwError specifies the completion status for
  3391.           the overlapped operation as indicated by
  3392.           lpOverlapped.  cbTransferred specifies the number
  3393.           of bytes sent.  This function does not return a
  3394.           value.
  3395.           
  3396.           Returning from this function allows invocation of
  3397.           another pending completion routine for this
  3398.           socket.  In Win32 environments, all waiting
  3399.           completion routines are called before the
  3400.           alterable thread's wait is satisfied with a return
  3401.           code of WSA_IO_COMPLETION.  The completion
  3402.           routines may be called in any order, not
  3403.           necessarily in the same order the overlapped
  3404.           operations are completed.  However, the posted
  3405.           buffers are guaranteed to be sent in the same
  3406.           order they are supplied
  3407.           
  3408.           If no buffer space is available within the
  3409.           transport system to hold the data to be
  3410.           transmitted, sendto() will block unless the socket
  3411.           has been placed in a non-blocking I/O mode.  On
  3412.           non-blocking stream-oriented sockets, the number
  3413.           of bytes written may be between 1 and the
  3414.           requested length, depending on buffer availability
  3415.           on both the local and foreign hosts.  The
  3416.           select(), WSAAsyncSelect() or WSACallbackSelect()
  3417.           call may be used to determine when it is possible
  3418.           to send more data.
  3419.           
  3420.           This function may be called in interrupt context
  3421.           provided that the socket option SO_INTERRUPT
  3422.           associated with s is TRUE, s is in non-blocking
  3423.           mode, and the MSG_INTERRUPT flag is set.  Note
  3424.           that the meaning of the return value in this case
  3425.           is changed.
  3426.           
  3427.           Flags may be used to influence the behavior of the
  3428.           function invocation beyond the options specified
  3429.           for the associated socket.  That is, the semantics
  3430.           of this function are determined by the socket
  3431.           options and the flags parameter.  The latter is
  3432.           constructed by or-ing any of the following values:
  3433.  
  3434.           Value     Meaning
  3435.           MSG_DONTROUTE
  3436.                     Specifies that the data should not be
  3437.                     subject to routing.  A WINSOCK service
  3438.                     provider may choose to ignore this flag;
  3439.                     see also the discussion of the
  3440.                     SO_DONTROUTE option in section Error!
  3441.                     Reference source not found..
  3442.           
  3443.           MSG_OOB   Send out-of-band data (stream style
  3444.                     socket such as SOCK_STREAM only; see
  3445.                     also section Error! Reference source not
  3446.                     found.)
  3447.           
  3448.           MSG_PARTIAL    Specifies that lpBuffer only
  3449.                     contains a partial message.  Note that
  3450.                     this flag will be ignored by transports
  3451.                     which do not support partial message
  3452.                     transmissions.
  3453.           
  3454.  
  3455. Return Value   If no error occurs, WSASendto() returns 0.
  3456.           Otherwise, a value of SOCKET_ERROR is returned,
  3457.           and a specific error code may be retrieved by
  3458.           calling WSAGetLastError().
  3459.  
  3460. Error Codes                   WSANOTINITIALISED   A
  3461.                               successful WSAStartup() must
  3462.                               occur before using this API.
  3463.           
  3464.           WSAENETDOWN         The network subsystem has
  3465.                               failed.
  3466.           
  3467.           WSAEACCES           The requested address is a
  3468.                               broadcast address, but the
  3469.                               appropriate flag was not set.
  3470.           
  3471.           WSAEINTR            The (blocking) call was
  3472.                               canceled via
  3473.                               WSACancelBlockingCall().
  3474.           
  3475.           WSAEINPROGRESS      A blocking PII operation is in
  3476.                               progress.
  3477.  
  3478.           WSAEFAULT           The lpBuffer or lpTo
  3479.                               parameters are not part of the
  3480.                               user address space, or the
  3481.                               lpTo argument is too small
  3482.                               (less than the sizeof a struct
  3483.                               sockaddr).
  3484.           
  3485.           WSAENETRESET        The connection must be reset
  3486.                               because the Winsock provider
  3487.                               dropped it.
  3488.           
  3489.           WSAENOBUFS          The Winsock provider reports a
  3490.                               buffer deadlock.
  3491.           
  3492.           WSAENOTCONN         The socket is not connected
  3493.                               (connection-oriented sockets
  3494.                               only)
  3495.           
  3496.           WSAENOTSOCK         The descriptor is not a
  3497.                               socket.
  3498.           
  3499.           WSAEOPNOTSUPP       MSG_OOB was specified, but the
  3500.                               socket is not stream style
  3501.                               such as type SOCK_STREAM, out-
  3502.                               of-band data is not supported
  3503.                               in the communication domain
  3504.                               associated with this socket,
  3505.                               or the socket is
  3506.                               unidirectional and supports
  3507.                               only receive operations.
  3508.           
  3509.           WSAESHUTDOWN        The socket has been shutdown;
  3510.                               it is not possible to
  3511.                               WSASendto() on a socket after
  3512.                               shutdown() has been invoked
  3513.                               with how set to SD_SEND or
  3514.                               SD_BOTH.
  3515.           
  3516.           WSAEWOULDBLOCK      There are too many outstanding
  3517.                               overlapped I/O requests.
  3518.           
  3519.           WSAEMSGSIZE         The socket is message-
  3520.                               oriented, and the message is
  3521.                               larger than the maximum
  3522.                               supported by the underlying
  3523.                               transport.
  3524.           
  3525.           WSAEINVAL           The socket has not been bound
  3526.                               with bind(), or the socket is
  3527.                               not created with the
  3528.                               overlapped flag.
  3529.           
  3530.           WSAECONNABORTED     The virtual circuit was
  3531.                               aborted due to timeout or
  3532.                               other failure.
  3533.           
  3534.           WSAECONNRESET       The virtual circuit was reset
  3535.                               by the remote side.
  3536.           
  3537.           WSAEADDRNOTAVAIL    The specified address is not
  3538.                               available from the local
  3539.                               machine.
  3540.           
  3541.           WSAEAFNOSUPPORT     Addresses in the specified
  3542.                               family cannot be used with
  3543.                               this socket.
  3544.           
  3545.           WSAEDESTADDRREQ     A destination address is
  3546.                               required.
  3547.           
  3548.           WSAENETUNREACH      The network can't be reached
  3549.                               from this host at this time.
  3550.           
  3551. See Also  WSACloseEvent(),WSACreateEvent(),
  3552.           WSAGetOverlappedResult(), WSASocket(),
  3553.           WSAWaitForMultipleEvents()
  3554. WSASocket()
  3555. Description    Create a socket which is bound to a specific
  3556.           transport service provider.
  3557.  
  3558. { May be revised to use PROTOCOL_INFO as an input param in
  3559.           place of af, type, protocol parameters}
  3560.  
  3561.           #include <winsock2.h>
  3562.  
  3563.           SOCKET WSAAPI WSASocket ( int af, int type, int
  3564.           protocol, int iProviderID, int iFlags);
  3565.  
  3566.           
  3567.           af        An address family specification.  The
  3568.                     only format currently supported is
  3569.                     PF_INET, which is the ARPA Internet
  3570.                     address format.
  3571.           
  3572.           type      A type specification for the new socket.
  3573.           
  3574.           protocol  A particular protocol to be used with
  3575.                     the socket, or 0 if the caller does not
  3576.                     wish to specify a protocol.
  3577.           
  3578.           iProviderID    The identifier of the service
  3579.                     provider to be selected.
  3580.           
  3581.           iFlags    The socket attribute specification.
  3582.  
  3583. Remarks   WSASocket() causes a socket descriptor and any
  3584.           related resources to be allocated and bound to the
  3585.           transport service provider specified by
  3586.           iProviderID.  The provider IDs of service
  3587.           providers can be obtained by using
  3588.           WSAEnumProviders().   If iProviderID is set to be
  3589.           -1, this indicates to the Winsock DLL that it
  3590.           should determine for itself which service provider
  3591.           to use based on the supplied af, type, and
  3592.           protocol parameters.
  3593.           
  3594.           If protocol is not specified (i.e., equal to
  3595.           zero), the default for the specified socket type
  3596.           is used.  However, the address family may be given
  3597.           as AF_UNSPEC (unspecified), in which case the
  3598.           protocol parameter must be specified.  The
  3599.           protocol number to use is particular to the
  3600.           "communication domain'' in which communication is
  3601.           to take place.
  3602.           
  3603.           The following type specifications may be supported
  3604.           (all sockets are bi-directional unless specified
  3605.           otherwise):
  3606.           
  3607.            Type                    Explanation
  3608.            SOCK_STREAM             Alias for
  3609.                                     SOCK_REL_STREAM.
  3610.            
  3611.            SOCK_DGRAM              Alias for
  3612.                                     SOCK_UNREL_DGRAM.
  3613.            
  3614.            SOCK_SEQPACKET          Alias for
  3615.                                     SOCK_REL_DSTREAM.
  3616.            
  3617.            SOCK_RAW                Raw socket.
  3618.            
  3619.            SOCK_REL_STREAM         Connection-oriented
  3620.                                     reliable, unduplicated,
  3621.                                     sequenced, byte
  3622.                                     streamwith an out-of-
  3623.                                     band data transmission
  3624.                                     mechanism.  Uses TCP
  3625.                                     for the Internet
  3626.                                     address family.
  3627.            
  3628.            SOCK_REL_DSTREAM        Connection-oriented
  3629.                                     reliable, unduplicated,
  3630.                                     sequenced, message
  3631.                                     streamwith an out-of-
  3632.                                     band data transmission
  3633.                                     mechanism.
  3634.            
  3635.            SOCK_UNREL_DSTREAM      Connection-oriented
  3636.                                     unreliable,
  3637.                                     unduplicated,
  3638.                                     sequenced, message
  3639.                                     streamwith an out-of-
  3640.                                     band data transmission
  3641.                                     mechanism.
  3642.            
  3643.            SOCK_REL_UNISEND_DSTREAMConnection-oriented,
  3644.                                     reliable, one-way (send
  3645.                                     only), unduplicated,
  3646.                                     sequenced, message
  3647.                                     stream. The matching
  3648.                                     socket at the remote
  3649.                                     side need to be of
  3650.                                     style
  3651.                                     SOCK_REL_UNIRECV_DSTREA
  3652.                                     M.
  3653.            
  3654.            SOCK_REL_UNIRECV_DSTREAMConnection-oriented,
  3655.                                     reliable, one-way
  3656.                                     (receive only),
  3657.                                     unduplicated,
  3658.                                     sequenced, message
  3659.                                     stream.  The matching
  3660.                                     socket at the remote
  3661.                                     side need to be of
  3662.                                     style
  3663.                                     SOCK_REL_UNISEND_DSTREA
  3664.                                     M.
  3665.            
  3666.            SOCK_UNREL_UNISEND_DSTREAM   Connection-
  3667.                                     oriented, unreliable,
  3668.                                     one-way (send only),
  3669.                                     unduplicated,
  3670.                                     sequenced, message
  3671.                                     stream. The matching
  3672.                                     socket at the remote
  3673.                                     side need to be of
  3674.                                     style
  3675.                                     SOCK_UNREL_UNIRECV_DSTR
  3676.                                     EAM.
  3677.            
  3678.            SOCK_UNREL_UNIRECV_DSTREAM   Connection-
  3679.                                     oriented, unreliable,
  3680.                                     one-way (receive only),
  3681.                                     unduplicated,
  3682.                                     sequenced, message
  3683.                                     stream.  The matching
  3684.                                     socket at the remote
  3685.                                     side need to be of
  3686.                                     style
  3687.                                     SOCK_UNREL_UNISEND_DSTR
  3688.                                     EAM.
  3689.            
  3690.            SOCK_REL_DGRAM          Connectionless,
  3691.                                     reliable, datagram.
  3692.            
  3693.            SOCK_UNREL_DGRAM        Connectionless,
  3694.                                     unreliable, datagram.
  3695.            
  3696.            SOCK_REL_ISOCH_DSTREAM  Connection-oriented
  3697.                                     reliable, unduplicated,
  3698.                                     sequenced, isochronous,
  3699.                                     message streamwith an
  3700.                                     out-of-band data
  3701.                                     transmission mechanism.
  3702.            
  3703.            SOCK_UNREL_ISOCH_DSTREAMConnection-oriented
  3704.                                     unreliable,
  3705.                                     unduplicated,
  3706.                                     sequenced, isochronous,
  3707.                                     message streamwith an
  3708.                                     out-of-band data
  3709.                                     transmission mechanism.
  3710.            
  3711.            SOCK_UNREL_ISOCH_STREAM Connection-oriented
  3712.                                     unreliable,
  3713.                                     unduplicated,
  3714.                                     sequenced, isochronous,
  3715.                                     byte streamwith an out-
  3716.                                     of-band data
  3717.                                     transmission mechanism.
  3718.               
  3719.           The iFlags parameter may be used to specify the
  3720.           attributes of the socket by or-ing any of the
  3721.           following Flags:
  3722.  
  3723.           Flag      Meaning
  3724.           WSA_FLAG_OVERLAPPED
  3725.                     This flag causes an overlapped socket to
  3726.                     be created. Overlapped sockets must
  3727.                     utilize WSASend(), WSASendto(),
  3728.                     WSARecv(), WSARecvfrom() for I/O
  3729.                     operations, and allows multiple of these
  3730.                     to be initiated and in progress
  3731.                     simultaneously. Overlapped sockets are
  3732.                     always non-blocking.
  3733.           
  3734.           Connection-oriented sockets such as SOCK_STREAM
  3735.           provide full-duplex connections, and must be in a
  3736.           connected state before any data may be sent or
  3737.           received on it.  A connection to another socket is
  3738.           created with a connect() call.  Once connected,
  3739.           data may be transferred using send()/WSASend() and
  3740.           recv()/WSARecv() calls.  When a session has been
  3741.           completed, a closesocket() must be performed.  Out-
  3742.           of-band data may also be transmitted as described
  3743.           in send() and received as described in recv().
  3744.           
  3745.           The communications protocols used to implement a
  3746.           reliable, connection-oriented socket ensure that
  3747.           data is not lost or duplicated.  If data for which
  3748.           the peer protocol has buffer space cannot be
  3749.           successfully transmitted within a reasonable
  3750.           length of time,  the connection is considered
  3751.           broken and subsequent calls will fail with the
  3752.           error code set to WSAETIMEDOUT.
  3753.           
  3754.           Connectionless, message-oriented sockets allow
  3755.           sending and receiving of datagrams to and from
  3756.           arbitrary peers using sendto()/WSASendto() and
  3757.           recvfrom()/WSARecvFrom().  If such a socket is
  3758.           connect()ed to a specific peer, datagrams may be
  3759.           send to that peer using send()/WSASend() and may
  3760.           be received from (only) this peer using
  3761.           recv()/WSARecv().
  3762.  
  3763.  
  3764. Return Value   If no error occurs, WSASocket() returns a
  3765.           descriptor referencing the new socket.  Otherwise,
  3766.           a value of INVALID_SOCKET is returned, and a
  3767.           specific error code may be retrieved by calling
  3768.           WSAGetLastError().
  3769.  
  3770. Error Codes                   WSANOTINITIALISED   A
  3771.                               successful WSAStartup() must
  3772.                               occur before using this API.
  3773.           
  3774.           WSAENETDOWN         The network subsystem has
  3775.                               failed.
  3776.           
  3777.           WSAEAFNOSUPPORT     The specified address family
  3778.                               is not supported.
  3779.           
  3780.           WSAEINPROGRESS      A blocking Winsock call is in
  3781.                               progress, or the service
  3782.                               provider is still processing a
  3783.                               callback function (see section
  3784.                               Error! Reference source not
  3785.                               found.).
  3786.           
  3787.           WSAEMFILE           No more socket descriptors are
  3788.                               available.
  3789.           
  3790.           WSAENOBUFS          No buffer space is available.
  3791.                               The socket cannot be created.
  3792.           
  3793.           WSAEPROTONOSUPPORT  The specified protocol is not
  3794.                               supported.
  3795.           
  3796.           WSAEPROTOTYPE       The specified protocol is the
  3797.                               wrong type for this socket.
  3798.           
  3799.           WSAESOCKTNOSUPPORT  The specified socket type is
  3800.                               not supported in this address
  3801.                               family.
  3802.  
  3803. See Also  accept(), bind(), connect(), getsockname(),
  3804.           getsockopt(), setsockopt(), listen(), recv(),
  3805.           recvfrom(), select(), send(), sendto(),
  3806.           shutdown(), ioctlsocket().
  3807. WSACreateEvent()
  3808. Description    Creates a new event object.
  3809.  
  3810.           #include <winsock2.h>
  3811.  
  3812.           WSAEVENT WSAAPI WSACreateEvent( VOID );
  3813.  
  3814. Remarks   The event object created by this function is
  3815.           manual reset, with an initial state of
  3816.           nonsignaled. If a Win32 application desires auto
  3817.           reset events, it may call the native CreateEvent()
  3818.           Win32 API directly.
  3819.  
  3820.           The Win32 implementation of this function is:
  3821.  
  3822.           #define WSACreateEvent() \
  3823.                CreateEvent( NULL, FALSE, FALSE, NULL );
  3824.  
  3825. Return Value   If the function succeeds, the return value is
  3826.           the handle of the event object.
  3827.  
  3828.           If the function fails, the return value is
  3829.           WSA_INVALID_EVENT. To get extended error
  3830.           information, call WSAGetLastError().
  3831.           
  3832. Error Codes                   ERROR_NOT_ENOUGH_MEMORY Not
  3833.                               enough free memory available
  3834.                               to create the event object.
  3835.           
  3836. See Also  WSACloseEvent().
  3837. WSACloseEvent()
  3838. Description    Closes an open event object handle.
  3839.  
  3840.           #include <winsock2.h>
  3841.  
  3842.           BOOL WSAAPI WSACloseEvent( WSAEVENT hEvent );
  3843.  
  3844.           hEvent    Identifies an open event object handle.
  3845.  
  3846. Remarks   The Win32 implementation of this function is:
  3847.  
  3848.           #define WSACloseEvent( h ) \
  3849.                CloseHandle( h )
  3850.  
  3851. Return Value   If the function succeeds, the return value is
  3852.           TRUE.
  3853.  
  3854.           If the function fails, the return value is FALSE.
  3855.           To get extended error information, call
  3856.           WSAGetLastError().
  3857.  
  3858. Error Codes                   ERROR_INVALID_HANDLE
  3859.                               hEvent is not a valid event
  3860.                               object handle.
  3861.           
  3862. See Also  WSACreateEvent().
  3863. WSAWaitForMultipleEvents()
  3864. Description    Returns either when any one or when all of
  3865.           the specified event objects are in the signaled
  3866.           state, or when the time-out interval elapses.
  3867.  
  3868.           #include <winsock2.h>
  3869.  
  3870.           DWORD WSAAPI WSAWaitForMultipleEvents( DWORD
  3871.           cEvents, const WSAEVENT FAR * lphEvents, BOOL
  3872.           fWaitAll, DWORD dwTimeout, BOOL fAlertable );
  3873.  
  3874.           cEvents   Specifies the number of event object
  3875.                     handles in the array pointed to by
  3876.                     lphEvents. The maximum number of event
  3877.                     object handles is
  3878.                     WSA_MAXIMUM_WAIT_EVENTS.
  3879.           
  3880.           lphEvents Points to an array of event object
  3881.                     handles.
  3882.           
  3883.           fWaitAll  Specifies the wait type. If TRUE, the
  3884.                     function returns when all event objects
  3885.                     in the lphEvents array are signaled at
  3886.                     the same time. If FALSE, the function
  3887.                     returns when any one of the event
  3888.                     objects is signaled. In the latter case,
  3889.                     the return value indicates the event
  3890.                     object whose state caused the function
  3891.                     to return.
  3892.           
  3893.           dwTimeout Specifies the time-out interval, in
  3894.                     milliseconds. The function returns if
  3895.                     the interval elapses, even if conditions
  3896.                     specified by the fWaitAll parameter are
  3897.                     not satisfied. If dwTimeout is zero, the
  3898.                     function tests the state of the
  3899.                     specified event objects and returns
  3900.                     immediately. If dwTimeout is
  3901.                     WSA_INFINITE, the function's time-out
  3902.                     interval never elapses.
  3903.           
  3904.           fAlertable     Specifies whether the function
  3905.                     returns when the system queues an I/O
  3906.                     completion routine for execution by the
  3907.                     calling thread. If TRUE, the function
  3908.                     returns and the completion routine is
  3909.                     executed. If FALSE, the function does
  3910.                     not return and the completion routine is
  3911.                     not executed. Note that this parameter
  3912.                     is ignored in Win16.
  3913.  
  3914. Remarks   In nonpreemptive environments (Win16), the
  3915.           blocking hook is called if this function must wait
  3916.           for the event(s) to become signaled. In preemptive
  3917.           environments (Win32), the blocking hook is never
  3918.           called from within this function.
  3919.  
  3920.           The Win32 implementation for this function is:
  3921.  
  3922.           #define WSAWaitForMultipleEvents( c, p, w, t, a )
  3923.           \
  3924.                WaitForMultipleEventsEx( (c), (p), (w), (t),
  3925.           (a) )
  3926.  
  3927. Return Value   If the function succeeds, the return value
  3928.           indicates the event object that caused the
  3929.           function to return.
  3930.  
  3931.           If the function fails, the return value is
  3932.           WSA_WAIT_FAILED. To get extended error
  3933.           information, call WSAGetLastError().
  3934.  
  3935.           The return value upon success is one of the
  3936.           following values:
  3937.  
  3938.           Value          Meaning
  3939.           WSA_WAIT_OBJECT_0
  3940.           to
  3941.            (WSA_WAIT_OBJECT_0
  3942.           + cObjects - 1) If fWaitAll is TRUE, the return
  3943.           value indicates that the state of all specified
  3944.           event objects is signaled. If fWaitAll is FALSE,
  3945.           the return value minus WAIT_OBJECT_0 indicates the
  3946.           lphEvents array index of the object that satisfied
  3947.           the wait.
  3948.  
  3949.           WAIT_IO_COMPLETION (Win32 only) One or more I/O
  3950.           completion routines are queued for execution.
  3951.  
  3952.           WSA_WAIT_TIMEOUT The time-out interval elapsed and
  3953.           the conditions specified by the fWaitAll parameter
  3954.           are not satisfied.
  3955.  
  3956. Error Codes                   ERROR_NOT_ENOUGH_MEMORY Not
  3957.                               enough free memory available
  3958.                               to complete the operation
  3959.           
  3960.           ERROR_INVALID_HANDLE     One or more of the values
  3961.                               in the lphEvents array is not
  3962.                               a valid event object handle.
  3963.           
  3964.           ERROR_INVALID_PARAMETER The cEvents parameter does
  3965.                               not contain a valid handle
  3966.                               count.
  3967.           
  3968. See Also  WSACreateEvent(), WSASetEvent().
  3969. WSASetEvent()
  3970. Description    Sets the state of the specified event object
  3971.           to signaled.
  3972.  
  3973.           #include <winsock2.h>
  3974.  
  3975.           BOOL WSAAPI WSASetEvent( WSAEVENT hEvent );
  3976.  
  3977.           hEvent    Identifies an open event object handle.
  3978.           
  3979. Remarks   The Win32 implementation of this function is:
  3980.  
  3981.           #define WSASetEvent( h ) \
  3982.                SetEvent( h )
  3983.  
  3984. Return Value   If the function succeeds, the return value is
  3985.           TRUE.
  3986.  
  3987.           If the function fails, the return value is FALSE.
  3988.           To get extended error information, call
  3989.           WSAGetLastError().
  3990.  
  3991. Error Codes                   ERROR_INVALID_HANDLE
  3992.                               hEvent is not a valid event
  3993.                               object handle.
  3994.           
  3995. See Also  WSACreateEvent(), WSAResetEvent().
  3996. WSAResetEvent()
  3997. Description    Resets the state of the specified event
  3998.           object to nonsignaled.
  3999.  
  4000.           #include <winsock2.h>
  4001.  
  4002.           BOOL WSAAPI WSAResetEvent( WSAEVENT hEvent );
  4003.  
  4004.           hEvent    Identifies an open event object handle.
  4005.  
  4006. Remarks   The Win32 implementation of this function is:
  4007.  
  4008.           #define WSAResetEvent( h )
  4009.                ResetEvent( h )
  4010.  
  4011. Return Value   If the function succeeds, the return value is
  4012.           TRUE.
  4013.  
  4014.           If the function fails, the return value is FALSE.
  4015.           To get extended error information, call
  4016.           WSAGetLastError().
  4017.  
  4018. Error Codes                   ERROR_INVALID_HANDLE
  4019.                               hEvent is not a valid event
  4020.                               object handle.
  4021.           
  4022. See Also  WSACreateEvent(), WSASetEvent().
  4023. WSAGetOverlappedResult()
  4024. Description    Returns the results of an overlapped
  4025.           operation on the specified socket.
  4026.  
  4027.           #include <winsock2.h>
  4028.  
  4029.           BOOL WSAAPI WSAGetOverlappedResult( SOCKET sock,
  4030.           LPWSAOVERLAPPED lpOverlapped, LPDWORD
  4031.           lpcbTransfer, BOOL fWait, LPDWORD lpdwFlags );
  4032.  
  4033.           sock      Identifies the socket. This is the same
  4034.                     socket that was specified when the
  4035.                     overlapped operation was started by a
  4036.                     call to WSARecv(), WSARecvFrom(),
  4037.                     WSASend(), WSASendTo(), WSAConnect(), or
  4038.                     WSAAccept().
  4039.           
  4040.           lpOverlapped   Points to a WSAOVERLAPPED structure
  4041.                     that was specified when the overlapped
  4042.                     operation was started.
  4043.           
  4044.           lpcbTransfer   Points to a 32-bit variable that
  4045.                     receives the number of bytes that were
  4046.                     actually transferred by a send or
  4047.                     receive operation.
  4048.           
  4049.           fWait     Specifies whether the function should
  4050.                     wait for the pending overlapped
  4051.                     operation to complete. If TRUE, the
  4052.                     function does not return until the
  4053.                     operation has been completed. If FALSE
  4054.                     and the operation is still pending, the
  4055.                     function returns FALSE and the
  4056.                     WSAGetLastError function returns
  4057.                     WSA_IO_INCOMPLETE.
  4058.           
  4059.           lpdwFlags Points to a 32-bit variable that will
  4060.                     receive one or more flags that
  4061.                     supplement the completion status. For
  4062.                     example, if partial data is received
  4063.                     over a message-oriented transport, this
  4064.                     is indicated here.
  4065.  
  4066. Remarks   The results reported by the
  4067.           WSAGetOverlappedResult() function are those of the
  4068.           specified socket's last overlapped operation to
  4069.           which the specified WSAOVERLAPPED structure was
  4070.           provided, and for which the operation's results
  4071.           were pending. A pending operation is indicated
  4072.           when the function that started the operation
  4073.           returns FALSE, and the WSAGetLastError() function
  4074.           returns WSA_IO_PENDING. When an I/O operation is
  4075.           pending, the function that started the operation
  4076.           resets the hEvent member of the WSAOVERLAPPED
  4077.           structure to the nonsignaled state. Then when the
  4078.           pending operation has been completed, the system
  4079.           sets the event object to the signaled state.
  4080.  
  4081.           If the fWait parameter is TRUE,
  4082.           WSAGetOverlappedResult() determines whether the
  4083.           pending operation has been completed by waiting
  4084.           for the event object to be in the signaled state.
  4085.  
  4086. Return Value   If the function succeeds, the return value is
  4087.           TRUE.
  4088.  
  4089.           If the function fails, the return value is FALSE.
  4090.           To get extended error information, call
  4091.           WSAGetLastError().
  4092.  
  4093. Error Codes                   ERROR_INVALID_HANDLE     One
  4094.                               of the handles involved with
  4095.                               this operation is invalid.
  4096.                               Either sock is not a valid
  4097.                               socket handle, or the hEvent
  4098.                               field of the WSAOVERLAPPED
  4099.                               structure does not contain a
  4100.                               valid event object handle.
  4101.           
  4102.           ERROR_INVALID_PARAMETER One of the parameters is
  4103.                               unacceptable.
  4104.           
  4105.           ERROR_IO_INCOMPLETE fWait is FALSE and the I/O
  4106.                               operation has not yet
  4107.                               completed.
  4108.           
  4109. See Also  WSACreateEvent(), WSAWaitForMultipleEvents(),
  4110.           WSARecv(), WSARecvFrom(), WSASend(), WSASendTo(),
  4111.           WSAConnect(), WSAAccept().
  4112. WSAGetQoSByName()
  4113. Description    Initializes the QoS based on a template.
  4114.  
  4115.           #include <winsock2.h>
  4116.  
  4117.           BOOL WSAAPI WSAGetQoSByName( SOCKET sock, LPWSABUF
  4118.           lpQosName, LPQOS lpQoS);
  4119.  
  4120.           sock      Identifies the socket. This is the same
  4121.                     socket that was specified when the
  4122.                     overlapped operation was started by a
  4123.                     call to WSARecv(), WSARecvFrom(),
  4124.                     WSASend(), WSASendTo(), WSAConnect(), or
  4125.                     WSAAccept().
  4126.           
  4127.           lpQosName Specifies the QoS template name
  4128.  
  4129. Remarks   Initializes the QoS structure based on a named
  4130.           template.
  4131.  
  4132. Return Value   If the function succeeds, the return value is
  4133.           TRUE.
  4134.  
  4135.           If the function fails, the return value is FALSE.
  4136.           To get extended error information, call
  4137.           WSAGetLastError().
  4138. Error Codes
  4139.           ERROR_INVALID_PARAMETER The specified QoS template
  4140.                               is invalid.
  4141.           
  4142. See Also  WSAConnect(), WSAAccept(), getsockopt(), select(),
  4143.           WSAAsyncSelect().
  4144. Winsock 2.0 Header File - Winsock2.h
  4145.  
  4146. /* WINSOCK2.H--definitions to be used with the WINSOCK2.DLL
  4147. and WINSOCK2 applications.
  4148.  *
  4149.  * This header file corresponds to version 2.0 of the
  4150. Winsock specification.
  4151.  *
  4152.  * This file includes parts which are Copyright (c) 1982-
  4153. 1986 Regents
  4154.  * of the University of California.  All rights reserved.
  4155. The
  4156.  * Berkeley Software License Agreement specifies the terms
  4157. and
  4158.  * conditions for redistribution.
  4159.  */
  4160.  
  4161. #ifdef WIN32
  4162.  
  4163. #define WSATASK HANDLE
  4164.  
  4165. #else //WIN16
  4166.  
  4167. #define WSATASK HTASK
  4168.  
  4169. #endif // WIN32
  4170.  
  4171. typedef enum
  4172. {
  4173.      GuaranteedService,
  4174.      BestEffortService
  4175. } GUARANTEE;
  4176.  
  4177. typedef struct _flowparams
  4178. {
  4179.      int64          AverageBandwith;// In Bytes/sec
  4180.      int64          PeakBandwidth; // In Bytes/sec
  4181.      int64          BurstLength;   // In microseconds
  4182.      int64          Latency;  // In microseconds
  4183.      int64          DelayVariation;// In microseconds
  4184.      GUARANTEE levelOfGuarantee;// Guaranteed or
  4185.                          // Best Effort
  4186.      int32          CostOfCall;    // Reserved for future
  4187.                          // use, must be set to 0
  4188.      int32          ProviderId;    // Provider Identifier
  4189.      int32          SizePSP;  // Length of provider
  4190.                          // specific parameters
  4191.           UCHAR     ProviderSpecificParams[1];// provider
  4192. specific                                          //
  4193. parameters
  4194. } FLOWPARAMS;
  4195.  
  4196. typedef struct _QualityOfService
  4197. {
  4198.      FLOWPARAMS     ForwardFP;     // Caller(Initiator) to
  4199. callee
  4200.      FLOWPARAMS     BackwardFP;    // Callee to caller
  4201. } QOS, FAR * LPQOS;
  4202.  
  4203. typedef int (CALLBACK * LPCONDITIONPROC) (const struct
  4204. sockaddr FAR * CallerName,
  4205.                                           int CallerNamelen,
  4206.                                           LPWSABUF
  4207. lpCallerData,
  4208.                                           LPQOS lpSFlowspec,
  4209.                                           const struct
  4210. sockaddr FAR * CalleeName
  4211.                                           int CalleeNamelen,
  4212.                                           LPWSABUF
  4213. lpCalleeData,
  4214.                                           GROUP FAR * g,
  4215.                                           DWORD
  4216. dwCallbackData);
  4217.  
  4218. typedef stuct _WSANETWORKEVENTS {
  4219.        long lNetworkEvent,
  4220.        int iErrorCode
  4221. } WSANETWORKEVENTS, LPWSANETWORKEVENTS;
  4222.  
  4223. #define   WSAEDISCON    ????
  4224.  
  4225. _______________________________
  4226. 1Note that there is a timing window between the accept()
  4227. call and the call to WSAAsyncSelect() to change the events
  4228. or wMsg.  An application which desires a different wMsg for
  4229. the listening and accept()'ed sockets should ask for only
  4230. FD_ACCEPT events on the listening socket, then set
  4231. appropriate events after the accept().  Since FD_ACCEPT is
  4232. never sent for a connected socket and FD_READ, FD_WRITE,
  4233. FD_OOB, and FD_CLOSE are never sent for listening sockets,
  4234. this will not impose difficulties.
  4235. 2Note that there is a timing window between the accept()
  4236. call and the call to WSAEventSelect() to change the network
  4237. events or hEventObject.  An application which desires a
  4238. different hEventObject for the listening and accept()'ed
  4239. sockets should ask for only FD_ACCEPT network event on the
  4240. listening socket, then set appropriate network events after
  4241. the accept().  Since FD_ACCEPT never happens to a connected
  4242. socket and FD_READ, FD_WRITE, FD_OOB, and FD_CLOSE never
  4243. happen to listening sockets, this will not impose
  4244. difficulties.
  4245.